akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N, M;
  cin >> N >> M;
  vl A(N);
  rep(i, N) cin >> A[i];

  ll ans = 0;

  map<ll, ll> rem_cnt;
  rem_cnt[0]++;
  
  ll sum = 0;
  rep(i, N){
    sum += A[i] % M;
    sum %= M;
    
    rem_cnt[sum]++;
  }
  
  ll cnt;

  for(auto it = rem_cnt.begin(); it != rem_cnt.end(); it++){
    cnt = it->second;
    ans += cnt * (cnt - 1) / 2;
  }

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


Measured memory_bytes: 4992
import sys
import numpy as np
import itertools
# from decimal import Decimal
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
# 100 でLoop
ansLis = [0] * 10001
arr = np.array(ansLis)

for i in range(1, 100):
    for j in range(i, 100):
        for k in range(j, 100):
            tar = i*i + j*j + k*k + i*j + j*k + k*i
            if (tar > 10000):
                continue

            if (i == j and j == k):
                arr[tar] += 1
            elif (i != j) and (j != k):
                arr[tar] += 6
            else:
                arr[tar] += 3


for i in range(1, n + 1):
    print(arr[i])


Measured memory_bytes: 27116
#include <iostream>

using namespace std;

int main() {
    int a, b, c, N, flag;
    int array[100];

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

    for (int i = 0; i < N; i++) {
        if (array[i] % 2 == 0) {
            if (array[i] % 3 == 0 || array[i] % 5 == 0) {  
            } else {
                cout << "DENIED" << endl;
                return 0;
            }
        }
    }

    cout << "APPROVED" << endl;
}

Measured memory_bytes: 256
def schedule(A, q):
    count = 0
    while A != []:
        if A[0][1] <= q :
            count += A[0][1]
            w = A.pop(0)
            print(w[0], str(count))
        else :
            count += q
            A[0][1] -= q
            out = A.pop(0)
            A.append(out)

if __name__ == '__main__':
    n, q = input().split()
    n = int(n)
    q = int(q)
    que = [0]*n
    for i in range(n):
        name, time = input().split()
        que[i] = [name, int(time)]
    schedule(que, q)


Measured memory_bytes: 12908
import sys

# from collections import Counter, deque, defaultdict
# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
# N = int(input())
# A,B,C = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]

N, M = [int(x) for x in input().split()]
A = {int(input()) for _ in range(M)}

dp = [0] * (N + 1000)
dp[0] = 1

for i in range(N):
    if i + 1 not in A:
        dp[i + 1] += dp[i]
        # dp[i + 1] %= MOD
    if i + 2 not in A:
        dp[i + 2] += dp[i]
        # dp[i + 2] %= MOD

print(dp[N] % MOD)


Measured memory_bytes: 462708
# 2020-05-22
def main():
    n, m, k = [int(x) for x in input().split()]
    friends = [set() for _ in range(n)]
    blocks = [set() for _ in range(n)]
    for _ in range(m):
        a, b = [int(x) - 1 for x in input().split()]
        friends[a].add(b)
        friends[b].add(a)
    for _ in range(k):
        a, b = [int(x) - 1 for x in input().split()]
        blocks[a].add(b)
        blocks[b].add(a)

    networks = {}  # The dict of networks as sets. Keys are leaders.
    net_leaders = [-1] * n  # The leaders of the networks that the ones joined.
    visited = [False] * n
    for person in range(n):
        if visited[person]:
            continue
        network = set()
        network_add = network.add
        stack = [person]
        stack_append = stack.append
        stack_pop = stack.pop
        while stack:
            new = stack_pop()
            visited[new] = True
            net_leaders[new] = person
            network_add(new)
            for adj in friends[new]:
                if visited[adj]:
                    continue
                stack_append(adj)
        networks[person] = network

    answers = []
    answers_append = answers.append
    for person in range(n):
        net = networks[net_leaders[person]]
        ans = len(net) - len(friends[person]) - 1
        for block in blocks[person]:
            if block in net:
                ans -= 1
        answers_append(ans)

    print(*answers)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 122144
import java.util.Scanner;

public class Main {

	private static int[][] xy;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		xy = new int[n][2];

		for (int i = 0; i < n; i++) {
			xy[i][0] = sc.nextInt();
			xy[i][1] = sc.nextInt();
		}

		double l = 0;
		double r = 1001;
		int c = 0;
		while (c < 80) {
			double c1 = (l * 2 + r) / 3;
			double c2 = (l + r * 2) / 3;
			if (f(c1) < f(c2)) {
				r = c2;
			} else {
				l = c1;
			}
			c++;
		}

		System.out.println(String.format("%.8f", f(l)));
	}

	private static double f(double x) {
		double l = 0;
		double r = 1001;
		int c = 0;
		while (c < 80) {
			double c1 = (l * 2 + r) / 3;
			double c2 = (l + r * 2) / 3;
			if (g(x, c1) < g(x, c2)) {
				r = c2;
			} else {
				l = c1;
			}
			c++;
		}
		return g(x, l);
	}

	private static double g(double x, double y) {
		double a = 0.0;
		for (int i = 0; i < xy.length; i++) {
			double r = Math.sqrt((xy[i][0] - x) * (xy[i][0] - x) + (xy[i][1] - y) * (xy[i][1] - y));
			a = Math.max(a, r);
		}
		return a;
	}
}



Measured memory_bytes: 23124
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100010], n, mx1, mx2;
int main() {
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	sort(a + 1, a + n + 1);
	for(int i = 2; i <= n; i++) {
		if(a[i] == a[i - 1]) {
			int now = a[i];
			if(now > mx1) {
				mx2 = mx1;
				mx1 = now;
			} else if(now > mx2) {
				mx2 = now;
			}
			i++;
		}
	}
	printf("%lld", 1LL * mx1 * mx2);
} 

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

int main(){
	int n, d;
	vector<int> c[101];
	// poewr[i] := テ・ツ崢ス i テ」ツ?ョテヲツ按ヲテゥツ猟佚・ツ環?テ」ツδ淌」ツつオテ」ツつ、テ」ツδォテ」ツ?ョテヲツ閉ーテ・ツ?、テ」ツ?ョテ・ツ青暗ィツィツ?
	int power[101];
	
	while( cin >> n >> d, n || d ){
		// テ・ツ?・テ・ツ環?
		for(int i=0 ; i < n ; i++ ){
			int m;
			cin >> m;
			
			power[i] = 0;
			c[i] = vector<int>(m);
			for(int j=0 ; j < m ; j++ ){
				cin >> c[i][j];
				power[i] += c[i][j];
			}
		}
		
		bool is_remove = true;
		while( is_remove ){
			is_remove = false;
			
			for(int i=0 ; i < n ; i++ ){
				// テ・ツ崢ス i テ」ツ?ョテ」ツδ淌」ツつオテ」ツつ、テ」ツδォテ」ツつ津ゥツ卍、テ・ツ篠サテ」ツ?凖」ツつ凝」ツ?ィテ、ツサツョテ・ツョツ?
				int k = c[i].size() - 1;
				// テ・ツ崢ス i テ」ツ?古」ツδ淌」ツつオテ」ツつ、テ」ツδォテ」ツつ津ヲツ個?」ツ?」テ」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツ?ィテ」ツ??
				if( k < 0 ) continue;
				
				power[i] -= c[i][k];
				// テ・ツ青?・ツ崢ステ」ツ?ョテヲツ慊?・ツ、ツァテ」ツ?ィテヲツ慊?・ツーツ湘」ツつ津ヲツアツづ」ツつ?」ツつ?
				int max_p=0, min_p=1e+8;
				for(int j=0 ; j < n ; j++ ){
					max_p = max(max_p, power[j]);
					min_p = min(min_p, power[j]);
				}
				
				if( max_p - min_p <= d ){ // テ・ツ崢ス i テ」ツ?ョテ」ツδ淌」ツつオテ」ツつ、テ」ツδォテ」ツつ津ゥツ卍、テ・ツ篠サテ」ツ?ァテ」ツ?催」ツつ?
					c[i].pop_back();
					is_remove = true;
					break;
				}else{ // テゥツ卍、テ・ツ篠サテ」ツ?ァテ」ツ?催」ツ?ェテ」ツ??
					power[i] += c[i][k];
				}
			}
		}
		bool ans = true;
		for(int i=0 ; i < n ; i++ ){
			if( !c[i].empty() ) ans = false;
		}
		cout << (ans? "Yes" : "No") << endl;
	}
}

Measured memory_bytes: 1308
n = int(input())
s = input()

import random
base1 = 1007
mod1 = 10**9+7
modTank1 = [3000012541,3000012553,3000012563,3000012649,3000012683,3000012709]
mod1 = modTank1[random.randint(0,5)]
base1 = 1007
mod1 = 10**9+7
hash1 = [0]*(n+1)
power1 = [1]*(n+1)
for i,e in enumerate(s):
    hash1[i+1] = (hash1[i]*base1 + ord(e))%mod1
    power1[i+1] = (power1[i]*base1)%mod1
def rolling_hash(i, j):
    return (hash1[j]-hash1[i]*power1[j-i]%mod1)%mod1



hash = set()
l = 0
r = n
while r - l > 1:
    m = l + (r-l)//2
    hash = dict()
    flag = 0
    for i in range(n-m+1):
        h = rolling_hash(i, i+m)
        if h not in hash.keys():
            hash[h] = i
        elif hash[h]+m <= i:
            flag = 1
            break
    if flag == 1:
        l = m
    else:
        r = m

print(l)


Measured memory_bytes: 4524
import java.util.Scanner;

public class Main {
	public static void main(String arg[]) {

		Scanner sc = new Scanner(System.in);

		String s = sc.next();
		sc.close();
		int count = 0;

		for (int i = 0; i < 3; i++) {
			if (s.charAt(i) == '1') {
				count++;
			}
		}
		System.out.print(count);
	}
}


Measured memory_bytes: 24276
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] v = new int[n];
        for (int i = 0; i < n; i++) {
            int num = sc.nextInt();
            v[i] = num;
        }
        Arrays.sort(v);
        double total = v[0];
        for(int i = 1; i < n; i++) {
            total = ((total + v[i]) / 2);
        }
        System.out.println(total);
    }
}


Measured memory_bytes: 21844
#include <cstdio>

int main(){
    int l,m,n;
    long long s;
    scanf("%d",&n);
    s = 0;
    l = -1000000;
    m = 1000000;
    for(int i = 0;i < n;i++){
        int x;
        scanf("%d",&x);
        s += x;
        if(l < x){
            l = x;
        }
        if(m > x){
            m = x;
        }
    }
    printf("%d %d %lld\n",m,l,s);
    return 0;
}


Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x,long long int y) 
{ 
    long long int res = 1;     // Initialize result 
  // x=x;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x); 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x);  // Change x to x^2 
    } 
    return res; 
}
long long int power(long long int x,long long int y,long long int m) 
{ 
    long long int res = 1;     // Initialize result 
   x=x%m;
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x)%m; 
   
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x)%m;  // Change x to x^2 
    } 
    return res; 
}
void primeFactors(int n)  
{  
    // Print the number of 2s that divide n  
    while (n % 2 == 0)  
    {  
        cout << 2 << " ";  
        n = n/2;  
    }  
  
    // n must be odd at this point. So we can skip  
    // one element (Note i = i +2)  
    for (int i = 3; i <= sqrt(n); i = i + 2)  
    {  
        // While i divides n, print i and divide n  
        while (n % i == 0)  
        {  
            cout << i << " ";  
            n = n/i;  
        }  
    }  
  
    // This condition is to handle the case when n  
    // is a prime number greater than 2  
    if (n > 2)  
        cout << n << " ";  
}

long long int gcd(long long int a, long long int b){ 
    if (a == 0) 
        return b;  
    return gcd(b % a, a);  
 } 
 long long int lcm(long long int a, long long int b)  
 { 
     long long int temp;
    
    return (a*b)/gcd(a, b);  
 }
 
int main() {
   
    long long int n1,m1,t;
   // cin>>t;
   t=1;
    while(t--)
    {
   long long int i,j;
 //long long int b[1000000];
 //set<long long int >s;
       long long int f=1,p=0,z,o=0;
       double pie=3.141592653589793238;
    long long int c=0,n,m,l=0,r=0,k,min1=10000000000000,max2=-100;
 string s,s1;
      cin>>s>>s1;
      for(i=0;i<s.length();i++)
      {
      if(s[i]!=s1[i])
      o++;}
        cout<<o;

    }
 return 0;
}


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 2e7 + 9, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int freq[27];
int main()
{
int a,b,c;
cin>>a>>b>>c;
cout<<(a+b)*c/2<<endl;



    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<map>
#include<algorithm>
#include<set>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
int main(void){
    int n,count=0;
    cin>>n;
    set<int> ss;
    vector<int> v(n,0);
    for(int j=0;j<n;j++){
        cin>>v[j];
    }
    rep(i,n){
        if(ss.find(v[i])==ss.end()){
            ss.insert(v[i]);
            count++;
        }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>

int n,d1,d2;
bool G[700][700];

void build(int d){
	int D=d,b=0;
	while (!(D&3)){b++;D=D>>2;}
	if ((D&3)==2){
		for (int i=0;i<n+n;i++)
			for (int j=0;j<n+n;j++) 
				G[i][j]|=(((i>>b)&1));
	}
	else{
		for (int i=0;i<n+n;i++)
			for (int j=0;j<n+n;j++) 
				G[i][j]|=(((i>>b)+(j>>b))&1);
	}
}

int main(){
	scanf("%d%d%d",&n,&d1,&d2);
	build(d1);build(d2);
	int Counter=0;
	for (int i=0;i<n+n;i++)
		for (int j=0;j<n+n;j++)
			if (!G[i][j]){
				printf("%d %d\n",i,j);
				Counter++;
				if (Counter==n*n) return 0;
			}
}

Measured memory_bytes: 1280
import java.util.*;
public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long m = sc.nextLong();
        Map<Long,Long> map = new TreeMap<>();

        for(int i=0; i<n; i++){
           long a = sc.nextLong();
           long b = sc.nextLong();
            // (value,quantity)
           map.put(a, map.getOrDefault(a,0L) + b);
        }
        long ans = 0;
        long value = 0;

        for(Long price : map.keySet()){
            long quan = map.get(price);
            ans += quan;
            value += price * quan;
            if(ans >= m){
                value -= price * (ans - m);
                System.out.println(value);
                break;
            }
        }
    }
}

Measured memory_bytes: 98516
package main

import "fmt"

func main() {
	var N, T int
	fmt.Scan(&N, &T)

	var c, t int
	min := 9999
	for i := 0; i < N; i++ {
		fmt.Scan(&c, &t)
		if t <= T && c <= min {
			min = c
		}
	}

	if min != 9999 {
		fmt.Println(min)
		return
	}
	fmt.Println("TLE")
}


Measured memory_bytes: 512
eval'K,X,Y='+`dd`.split*?,
l=1
x,y,*s=X.abs,Y.abs
d=x+y
x,y=y,x if f=x<y
K%2-d%2<0&&p(-1)+exit
d!=K&&(l+=[~-d/K,1].max
v=K>(t=K*(l+=1&d-K*l)-d>>1)?0:t-t=K
a=K-t
2.upto(l){s<<[a,-t]
a+=q=[x+v-a,K].min
t-=K-q})
s<<[x,y]
p l
s.map{|a,b|a,b=b,a if f
p a*=X<=>0.1,b*=Y<=>0.1}

Measured memory_bytes: 43136
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  bool aaa = true;
  if (N % 2 == 0){
    for(int i = 0; i < N/2; i++){
      if (!(S.at(i) == S.at(i+N/2))){
        aaa = false;
        break;
      }
    }
    if (aaa){
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
/**Bismillahir Rahmanir Rahim.**/
/*
         Md.Fagun Molla
         18ICTCSE006
         BSMRSTU(SHIICT)
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll=long long;
using db=double;
///***************************************************** CONSTANTS ******************************************************///

int const N=1e6+3;
ll MOD=1e9+7,fact[N];
const long long inf=(long long)1e18;
const long double PI=3.14159265358979;

///************************************************ CONTAINER DEFINITIONS ***********************************************///

typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///************************************************ SHORT FORM KEYWORDS *************************************************///

#define PB push_back
#define F first
#define S second
#define MP make_pair
#define I insert
#define lb lower_bound
#define ub upper_bound
#define endl '\n'

///************************************************ SHORT FORM FUNCTIONS ************************************************///

#define loop(a,b) for(ll i=a;i<b;i++)
#define loopr(a,b) for(ll i=a-1;i>=b;i--)
#define mem(a,b) memset(a, b, sizeof(a) )
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define stll(x) stoll(x, nullptr, 10);
#define yes cout<<"YES"<<endl;
#define no cout<<"NO"<<endl;
#define mx(a) *max_element(all(a))
#define mn(a) *min_element(all(a))
#define all(a) a.begin(),a.end()
#define mxa(a,N) *max_element(a,a+N)
#define mna(a,N) *min_element(a,a+N)
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define io() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);


///************************************************ SOLUTION STARTS HERE ************************************************///
///======================================================================================================================///

void solve(){
	int n;
	cin>>n;
	int mx=0,c=0;
	for(int i=0; i<n; i++){
		int a,b;
		cin>>a>>b;
		if(a==b){
			c++;
			mx=max(mx,c);
		}
		else {
			c=0;
		}
	}
	if(mx<3) cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

}
int main()
{
    io();
    int T=1;//cin>>T;
    while(T--) solve();
    return 0;
}

/****************ALHAMDULILLAH******************/


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define FI(i,a,b) for(int i=(a);i<=(b);++i)
#define FD(i,b,a) for(int i=(b);i>=(a);--i)
using namespace std;
using LL = long long;
using PII = pair<int, int>;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    LL ans = 0;
    FI(b, k + 1, n) {
        int m = n / b;
        ans += 1LL * m * (b - k);
        int x = k + m * b;
        if (x <= n) ans += n - x + 1;
        if (k == 0) ans--;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int n,q,s[10000],t[500],i,j,count=0;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&t[i]);
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(t[i]==s[j]){
	count++;
	break;
      }
    }
  }

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



Measured memory_bytes: 2108
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  int a[10];
  std::cin >> a[0];
  std::cin >> a[1];
  std::cin >> a[2];
  sort(a,a+3);
  std::cout << a[2]*10+a[0]+a[1] << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long ll;
typedef long double  ld;
#define pii pair<ll,ll> 
#define pic pair<ll,char>
#define vi vector< ll > 
#define vvi vector< vi > 
#define vpi vector< pii > 
#define vvpi vector< vpi > 
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii > 
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
ll arr[21][21];
ll dp[1<<21];
ll n;
ll func(ll mask)
{
    if(__builtin_popcount(mask)==n)
        return 1;
    ll &ret = dp[mask];
    if(ret!=-1)
        return ret;
    ll index = __builtin_popcount(mask);
    ll i;
    ret = 0;
    for(i=0;i<n;i++)
    {
        if(arr[index][i] and (mask&(1<<i))==0)
            ret = (ret + func(mask|(1<<i)))%mod;
    }
    return ret;
}
signed main()
{
    fast;
    cin>>n;
    ll i,j;
    mem(dp,-1);
    for(i=0;i<n;i++)
        for(j=0;j<n;j++)
            cin>>arr[i][j];
    cout<<func(0);
}

Measured memory_bytes: 16640
#!/usr/bin/env python3
n = int(input())
t = input()
*c, = map(int, t.replace(*"W1").replace(*"R0"))

"""
1100 -> 0101 -> 0011
00
10110100 -> 00111100 -> 00011110 -> 00001111
"""

a = 0
i, j = 0, 1
while i + j < n:
    if c[i] == 1 and c[-j] == 0:
        a += 1
        i += 1
        j += 1
    elif c[i] == c[-j] == 0:
        i += 1
    elif c[i] == c[-j] == 1:
        j += 1
    else:
        i += 1
        j += 1
print(a)

Measured memory_bytes: 10976
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=1e9+7;
const llint big=2.19e18+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,k;cin>>n>>k;
	cout<<(n-2)/(k-1)+1<<endl;
	return 0;
}

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

typedef long long lint;
typedef unsigned long long ulint;
#define MOD 1000000007

lint gcd(lint a,lint b){
    if(a<b){
        lint tmp=a;
        a=b;
        b=tmp;
    }
    if(a%b==0) return b;
    return gcd(b,a%b);
}

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

    lint g,max=0;
    for(int i=0;i<N;i++){
        lint A;
        cin >> A;
        if(max<A) max=A;
        if(K==A){
            cout << "POSSIBLE" << endl;
            return 0;
        }
        if(i==0) g=A;
        else g=gcd(g,A);
    }
    if(max>=K && K%g==0) cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;

    return 0;
}

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

main(){
	int k,t;
	cin >> k >> t;
	int a[t];
	for(int i=0;i<t;i++){
		cin >> a[i];
	}
	sort(a, a+t);
	int max=a[t-1];
	if(t==1){
		cout << a[0]-1 <<endl;
	}else{
		for(int i=0;i<(t-1);i++){
			max-=a[i];
		}

		if(max<=1){
			cout << "0" <<endl;
		}else{
			cout << max-1 <<endl;
		}
	}
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	//n := r.nextInt()
	r.Scan(true)
	x := r.nextStringArray().toInts()

	ans := -1
	for p := 1; p <= 100; p++ {
		w := 0
		for _, xi := range x {
			w += pow(xi-p, 2, 0)
		}
		if ans < 0 || ans > w {
			ans = w
		}
	}
	fmt.Fprintln(stdout, ans)
}


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

using ll=long long;
#define int ll

#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=a;i--)
#define per(i,b) gnr(i,0,b)
#define pb push_back
#define eb emplace_back
#define a first
#define b second
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed
#ifdef LOCAL
#define dmp(x) cerr<<__LINE__<<" "<<#x<<" "<<x<<endl
#else
#define dmp(x) void(0)
#endif

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

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

template<class t,class u>
ostream& operator<<(ostream& os,const pair<t,u>& p){
	return os<<"{"<<p.a<<","<<p.b<<"}";
}

template<class t> ostream& operator<<(ostream& os,const vc<t>& v){
	os<<"{";
	for(auto e:v)os<<e<<",";
	return os<<"}";
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout<<fixed<<setprecision(20);
	
	int n,k;cin>>n>>k;
	k*=n;
	vi a(n);
	map<int,vi> idx;
	rep(i,n){
		cin>>a[i];
		idx[a[i]].pb(i);
	}
	vi w(n);
	for(auto kv:idx){
		int s=kv.b.size();
		kv.b.pb(kv.b[0]+n);
		rep(i,s){
			w[kv.b[i]]=kv.b[i+1]-kv.b[i]+1;
		}
	}
	const int inf=LLONG_MAX/3;
	const int L=60;
	vc<vi> nx{w};
	rep(_,L){
		vi&x=nx.back();
		vi y(n);
		rep(i,n)y[i]=min(inf,x[i]+x[(i+x[i])%n]);
		nx.pb(y);
	}
	int cur=0;
	per(i,L+1){
		if(cur+nx[i][cur%n]<=k)
			cur+=nx[i][cur%n];
	}
	if(cur==k)
		return 0;
	vi ans;
	set<int> has;
	rng(i,cur%n,n){
		if(has.count(a[i])){
			while(1){
				int v=ans.back();
				ans.pop_back();
				has.erase(v);
				if(v==a[i])break;
			}
		}else{
			ans.pb(a[i]);
			has.insert(a[i]);
		}
	}
	rep(i,ans.size()){
		cout<<ans[i];
		if(i<int(ans.size())-1)
			cout<<" ";
		else
			cout<<endl;
	}
}


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

public class Main {
    public static PrintWriter out;
    public static FastScanner in;

    int[] a;
    int n;
    private void solve(){
        String s = in.nextLine();
        a= new int[s.length()];
        n = s.length();
        for(int i=0;i<s.length();i++){
            a[i] =s.charAt(i)-'0';
        }
        long ret = 0;
        for(int i=0;i<(1<<n-1);i++){
            int st = 0;
            for(int j=0;j<n-1;j++){
                if((i & (1<<j))!=0){
                    ret+= calculate(st,j);
                    st = j+1;
                }
            }
            ret+=calculate(st,n-1);
            //out.println(ret + " "+i);
        }

        out.print(ret);
    }

    private long calculate(int s, int e){
        //out.println(s+" "+e);
        long v = 0;
        for(int i=s;i<=e;i++){
            v = v*10+a[i];
        }
        return v;
    }

    private void runIO() {
        in = new FastScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        solve();
        out.close();
    }
    private static class FastScanner {
        BufferedReader bufferedReader;
        StringTokenizer stringTokenizer;

        private FastScanner() {
            bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        }

        private String next() {
            if (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
                try {
                    stringTokenizer = new StringTokenizer(bufferedReader.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return stringTokenizer.nextToken();
        }

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

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

        private String nextLine() {
            String ret = "";
            try {
                ret = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return ret;
        }
    }

    public static void main(String[] args) {
        new Main().runIO();
    }
}


Measured memory_bytes: 21332
N = int(input())
c2 = 0

for i in range(1,N+1):
  c = 0
  if i%2 == 0:
    continue
  for j in range(1,i+1):
    if i%j==0:
      c += 1
  if c == 8:
    c2 +=1
    
print(c2)

Measured memory_bytes: 2940
def codefes17f_c():
    n = int(input())
    D = list(map(int, input().split()))
    D.sort()
    T = [0]
    for i, d in enumerate(D):
        if i%2: T.append(24-d)
        else: T.append(d)
    T.sort()
    ans = 12
    for i in range(n):
        ans = min(ans, T[i+1]-T[i])
    print(ans)

if __name__ == '__main__':
    codefes17f_c()

Measured memory_bytes: 9168
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
//#define num 1000000007
#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define up(a,b) (((a)%(b)==0)?((a)/(b)):((a)/(b))+1)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) (a>b)?(a>c)?a:c:(b>c)?b:c
#define min3(a,b,c) (a<b)?(a<c)?a:c:(b<c)?b:c
#define avg(a,b) ((a)+(b))/2
#define pb push_back
#define pob pop_back
#define mp make_pair
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define fi first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
 
ll mymod(ll a, ll b)
{
	return (a%b + b)%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll gcd(ll a, ll b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b, a%b);
}
bool prime[3001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=3000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=3000; i += p) 
                prime[i] = false; 
        } 
    } 
}
ll powe[20];
void power()
{
	powe[0]=1;
	REP(i,1,20)
	{
		powe[i]=(powe[i-1]*10)%num;
        if(powe[i]<0)
        powe[i]+=num;
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n,s;
	cin>>n>>s;
	ll A[n+1];
	REP(i,1,n+1)
	{
		cin>>A[i];
	}
	ll dp[n+1][s+1];
	ll dp2[s+1];
	REP(i,0,s+1) dp2[i]=0;
	REP(i,0,n+1) REP(j,0,s+1) dp[i][j]=0;
	REP(i,1,n+1)
	{
		if(A[i]<=s)
		{
		dp[i][A[i]]+=i;
		}
		REP(j,A[i]+1,s+1)
		{
				//cout<<dp[n][1]<<" cwjh\n";
				dp[i][j]+=dp2[j-A[i]];
				dp[i][j]=(dp[i][j]%num+num)%num;
		}
		REP(j,1,s+1)
		{
			dp2[j]+=dp[i][j];
			dp2[j]=(dp2[j]%num+num)%num;
		}
	}
	ll ans=0;
	REP(i,1,n+1)
	{
		ans+=dp[i][s]*(n-i+1);
		ans=mymod(ans,num);
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define MOD 998244353
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int n;
    cin >> n;
    vector<int> Graph[n];
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        Graph[a].push_back(b);
        Graph[b].push_back(a);
    }
    vector<int> dist(n, -1);
    dist[0] = 0;
    queue<int> Q;
    Q.push(0);
    while(!Q.empty()) {
        int now = Q.front();
        Q.pop();
        for(auto x : Graph[now]) {
            if(dist[x] != -1) continue;
            dist[x] = dist[now] + 1;
            Q.push(x);
        }
    }
    int count0 = 0;
    rep(i, n) {
        if(dist[i] % 2 == 0) count0++;
    }
    int count1 = n - count0;
    int now1 = 1, now2 = 2, now3 = 3;
    vector<int> Ans(n, -1);
    if(count0 <= n / 3) {
        rep(i, n) {
            if(dist[i] % 2 == 1) {
                if(now1 <= n) {
                    Ans[i] = now1;
                    now1 += 3;
                } else {
                    Ans[i] = now2;
                    now2 += 3;
                }
                if(now1 > n && now2 > n) break;
            }
        }
    }
    else if(count1 <= n / 3) {
        rep(i, n) {
            if(dist[i] % 2 == 0) {
                if(now1 <= n) {
                    Ans[i] = now1;
                    now1 += 3;
                } else {
                    Ans[i] = now2;
                    now2 += 3;
                }
                if(now1 > n && now2 > n) break;
            }
        }
    }
    else {
        rep(i, n) {
            if(dist[i] % 2 == 0) {
                if(now1 <= n) {
                    Ans[i] = now1;
                    now1 += 3;
                }
            } else {
                if(now2 <= n) {
                    Ans[i] = now2;
                    now2 += 3;
                }
            }
        }
    }
    rep(i, n) {
        if(Ans[i] == -1) {
            cout << now3 << ' ';
            now3 += 3;
        } else {
            cout << Ans[i] << ' ';
        }
    }
}


Measured memory_bytes: 18280
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);

		long a=sc.nextLong();
		long kaisu=0L;

		kaisu=a/11;
		kaisu*=2;
		a=a%11;

		if(a==0) {
			//
		}
		else if(a<=6 && a>=1) {
			kaisu++;
		}
		else if(a>=7){
			kaisu+=2;
		}
		System.out.println(kaisu);
	}
}

Measured memory_bytes: 23124
#include <iostream>

int main(){
    int a=0,b,c=1;
    for(int i=0;i<6;++i){
        std::cin>>b;
        b*=c;
        if(i%2==0)c*=5;
        else c*=2;
        a+=b;
    }
    std::cout<<((a>=1000)?1:0)<<std::endl;
    return 0;
}

Measured memory_bytes: 1164
import           Data.Graph.Inductive

readInts :: IO [Int]
readInts = map read . words <$> getLine

main :: IO ()
main = do
    [n, m] <- readInts
    abs <- sequence $ replicate m readInts
    print $ solve n abs

solve :: Int -> [[Int]] -> Int
solve n abs = length $ filter (not . isConnected) [ delEdge e gr | e <- es ]
  where
    vs = [1..n]
    es = [ (a, b) | [a, b] <- abs ]
    gr = mkUGraph vs es :: Gr () ()


Measured memory_bytes: 1020
-- F
local sub = string.sub
local insert = table.insert
s = io.read("*l")
x, y = io.read("*n", "*n", "*l")
local t1 = {}
local t2 = {}
local function isok(s, val)
	local has = {[0] = 0}
	local newHas = {}
	for i = 1, #s do
		local data = s[i]
		for _, hasV in pairs(has) do
			local ans = hasV + data
			if not newHas[ans] then
				newHas[ans] = ans
			end
			local ans = hasV - data
			if not newHas[ans] then
				newHas[ans] = ans
			end
		end
		has = newHas
		newHas = {}
	end
	if has[val] then
		return true
	end
end

local function solve()
	local n = 0
	local dirchange = false
	local dir = true -- x zhou
	-- first
	local st = 1
	while sub(s, st, st) == "F" do
		st = st + 1
	end
	x = x - (st - 1)
	for i = st, #s do
		local c = sub(s, i, i)
		if c == "F" then
			n = n + 1
		else
			if n ~= 0 then
				if dir then
					insert(t1, n)
				else
					insert(t2, n)
				end
				n = 0
				dirchange = false
			end
			dirchange = true
			dir = not dir
		end
	end
	if n ~= 0 then
		if dir then
			insert(t1, n)
		else
			insert(t2, n)
		end
	end
	if isok(t1, x) and isok(t2, y) then
		return "Yes"
	else
		return "No"
	end
end
print(solve())


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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll comb(ll a, ll b);
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    string s;
    cin >> s;
    string x[] = {
        "AKIHABARA",
        "AKIHBR",
        "KIHABR",
        "KIHBAR",
        "KIHBRA",
        "AKIHABR",
        "AKIHBAR",
        "AKIHBRA",
        "KIHABAR",
        "KIHABRA",
        "KIHBARA",
        "AKIHABAR",
        "AKIHABRA",
        "AKIHBARA",
        "KIHABARA",
        "KIHBR"};
    bool flg = false;
    rep(i, 16)
    {
        if (s == x[i])
        {
            flg = true;
            break;
        }
    }
    if (flg)
    {
        c("YES");
    }
    else
    {
        c("NO");
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b,c,d,e,f,g,h,x,y,ans;
    cin>>a>>b>>c>>d;
    e=a*c;
    f=a*d;
    g=b*c;
    h=b*d;
    x=max(e,f);
    y=max(x,g);
    ans=max(y,h);
    cout<<ans<<"\n";

}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st1, st2;
    cin >> st1 >> st2;

    vector<i_i> data1(st1.size()+1), data2(st2.size()+1);
    rep(i, st1.size()) {
        if (st1[i] == 'A') {
            data1[i+1].fir++;
        } else {
            data1[i+1].sec++;
        }
    }
    rep(i, data1.size()-1) {
        data1[i+1].fir += data1[i].fir;
        data1[i+1].sec += data1[i].sec;
    }

    rep(i, st2.size()) {
        if (st2[i] == 'A') {
            data2[i+1].fir++;
        } else {
            data2[i+1].sec++;
        }
    }
    rep(i, data2.size()-1) {
        data2[i+1].fir += data2[i].fir;
        data2[i+1].sec += data2[i].sec;
    }
    

    Int(n);
    rep(i, n) {
        int2(a, b); int2(c, d);
        int yui = data1[b].sec - data1[a-1].sec +
                    (data1[b].fir - data1[a-1].fir) * 2;
        int kyoko = data2[d].sec - data2[c-1].sec +
                    (data2[d].fir - data2[c-1].fir) * 2;
        if (yui % 3 == kyoko % 3) {
            std::cout << "YES" << std::endl;
        } else {
            std::cout << "NO" << std::endl;
        }
    }

    return 0;
}


Measured memory_bytes: 4048
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
As.sort()
mod = 10**9 + 7

if N%2==0:
    half = N//2
    for i in range(N):
        if i%2==0:
            x = i+1
        else:
            x = i
        if As[i]!=x:
            print(0)
            break
    else:
        print(pow(2, half, mod))
else:
    half = N//2
    if As[0]!=0:
        print(0)
        exit(0)
    for i in range(1, N):
        if i%2==1:
            x = i+1
        else:
            x = i
        if As[i]!=x:
            print(0)
            break
    else:
        print(pow(2, half, mod))    

Measured memory_bytes: 84156
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
const ll N=1e5+2;
set<ll>adj[N];
set<ll>rg[N];
bool vis[N];
ll n,m,k;
ll sze=0;
ll ind[N];
ll s[N];
void dfs(ll v,ll id)
{
	vis[v]=true;
	sze++;
	ind[v]=id;
	for(ll x:adj[v])
	{
		if(!vis[x])
		dfs(x,id);
	}
	return ;
}

int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	memset(vis,false,sizeof(vis));
 	cin>>n>>m>>k;
 	for(ll i=0;i<m;i++)
 	{
 		ll x,y;
 		cin>>x>>y;
 		adj[x].insert(y);
 		adj[y].insert(x);
 	}
 	for(ll i=0;i<k;i++)
 	{
 		ll x,y;
 		cin>>x>>y;
 		rg[x].insert(y);
 		rg[y].insert(x);
 	}
 	ll id=1;
 	for(ll i=1;i<=n;i++)
 	{
 		if(!vis[i])
 		{
 			sze=0;
 			dfs(i,++id);
 			s[id]=sze;
 		}
 		ll red=0;
 		for(ll x:rg[i])
 		{
 			if(ind[x]==ind[i] && adj[i].count(x)==0)
 			{
 				red++;
 			}
 		}
 		///cout<<i<<endl;
 		//cout<<s[ind[id]]<<" "<<adj[i].size()<<" "<<red<<endl;
 		cout<<s[ind[i]]-adj[i].size()-red-1<<" ";
 	}cout<<endl;
    return 0;
}

Measured memory_bytes: 31104
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

bool solve(int c[3][3]){
    int b[3]={c[0][0],c[0][1],c[0][2]};
    int a[3]={0,c[1][0]-b[0],c[2][0]-b[0]};
    REP(i,3) REP(j,3){
        if(c[i][j]!=a[i]+b[j]) return false;
    }
    return true;
}

bool lie(int c[3][3]){
    return c[0][0]+c[1][1]+c[2][2]==c[0][1]+c[1][2]+c[2][0]&&
           c[0][1]+c[1][2]+c[2][0]==c[0][2]+c[1][0]+c[2][1];
}

int main(){
    int c[3][3];
    REP(i,3) REP(j,3) cin>>c[i][j];
    if(lie(c)) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int c;
		int w = sc.nextInt();
		int n = sc.nextInt();
		int[] values = new int[w];
		for (int i = 0; i < values.length; i++) {
				values[i] = i + 1;
				}
		for(int i=0;i<n;i++){
			String str =sc.next();
			String[] ab=str.split(",");
			int a=Integer.parseInt(ab[0])-1;
			int b=Integer.parseInt(ab[1])-1;
			c=values[a];
			values[a]=values[b];
			values[b]=c;
		}
		for(int i=0;i<values.length;i++){
			System.out.println(values[i]);
		}
	}
}

Measured memory_bytes: 25836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
typedef long long int64;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
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 (a > b) { a = b; return 1; } return 0; }
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 };

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

	int N;
	cin >> N;

	rep(i, N) {
		int x;
		cin >> x;
		if (x % 2 == 0) {
			if (x % 3 != 0 && x % 5 != 0) {
				cout << "DENIED";
				return 0;
			}
		}
	}
	cout << "APPROVED";	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        if(a == 1 && b == 1) {
            System.out.println(1);
            return;
        }
        if(a == 1) {
            System.out.println(b - 2);
            return;
        }
        if(b == 1) {
            System.out.println(a - 2);
            return;
        }
        System.out.println((a - 2) * (b - 2));
    }
}


Measured memory_bytes: 21076
#include <stdio.h>
 
int main(void)
{
  int A, B, C, X;
  int a, b, c;
  int count = 0;
  scanf("%d%d%d%d", &A, &B, &C, &X);
  
  for (a = 0; a <= A; a++) 
    for (b = 0; b <= B; b++)
      for (c = 0; c <= C; c++) 
        if (X == 500*a + 100*b + 50*c)
          count++;
  printf("%d", count);
  return 0;
}

Measured memory_bytes: 256