akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define sz(arr) (int)(arr).size()
#define rng(arr) arr.begin(), arr.end()
#define show(x) cout << #x << " = " << x << endl;
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;
typedef long long int ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

#define Cins(T, n, xs) \
  vector<T> xs(n);     \
  for (int i = 0; i < n; ++i) cin >> xs[i]

void Main();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

void Main() {
  Cin(int, n, m);
  int min = 0, max = 1001001001;
  rep(i, m) {
    Cin(int, l, r);
    min = std::max(min, l);
    max = std::min(max, r);
  }
  int ans = std::max(0, max - min + 1);
  cout << std::min(n, ans) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int W,H,N;
  cin >> W >> H >> N;

  vector<vector<int> >paint(N,vector<int>(3,0));
  for(int i=0;i<N;i++){
    for(int j=0;j<3;j++){
      cin >> paint[i][j];
    }
  }

  vector<vector<int> >grid(H,vector<int>(W,0));

  for(int i=0;i<N;i++){
    if(paint[i][2] == 1){
      for(int j=0;j<H;j++){
        for(int k=0;k<paint[i][0];k++){
          grid[j][k] = 1;
        }
      }
    }
    if(paint[i][2] == 2){
      for(int j=0;j<H;j++){
        for(int k=paint[i][0];k<W;k++){
          grid[j][k] = 1;
        }
      }
    }
    if(paint[i][2] == 3){
      for(int j=0;j<paint[i][1];j++){
        for(int k=0;k<W;k++){
          grid[j][k] = 1;
        }
      }
    }
    if(paint[i][2] == 4){
      for(int j=paint[i][1];j<H;j++){
        for(int k=0;k<W;k++){
          grid[j][k] = 1;
        }
      }
    }
  }

  int ans = 0;

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(grid[i][j] == 0)
        ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
# from math import factorial,sqrt,ceil
# from itertools import permutations as permus
# from fractions import gcd
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
H,W = map(int,input().split())
h,w = map(int,input().split())

ans = H*W - (h*W + H*w - h*w)

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int, int> P;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(), (x).end()
#define pb push_back
int main()
{
    char i;
    cin >> i;
    if (isupper(i))
    {
        cout << "A" << endl;
    }
    else
    {
        cout << "a" << endl;
    }

    return 0;
}


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

typedef long long ll;
const int maxn=1e6+7;
const int inf=INT_MAX;
const ll inff=1e18;
const ll mod=1e9+7;
#define pii pair<int,int>
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(),(v).end()
#define int ll

#ifdef HNO2
#define IOS
#else
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#endif // HNO2

int n;

int cal(int x)
{
    if (x==1) return 1;
    else return 1+cal(x/2)*2;
}

int32_t main()
{
    IOS
    cin>>n;
    cout<<cal(n)<<endl;
}



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

int main(){
  int x,y;
  cin >> x >> y;
  int count = 0;
  if(x<4)
    count += 100000*(4-x);
  if(y<4)
    count += 100000*(4-y);
  if(x == 1 && y == 1)
    count += 400000;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;

int main()
{
    int a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;

    vector<ll> ans(3);
    ans[0] = a * x + b * y;
    ans[1] = 2 * c * max(x,y);
    ans[2] = 2 * c * min(x,y);
    if(x > y) ans[2] += a * (x - y);
    else if(x < y) ans[2] += b * (y - x);
    
    cout << *min_element(ans.begin(),ans.end()) << endl;

    return 0;
}

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

int main()
{
	int n;
	string str;
	cin >> n;
	getline(cin,str);	//nを入力する際、エンターでの改行をgetlineで読み込んで出力まで処理してしまうため、改行のみを読み込むgetlineを用意する。
	while (n--)
	{
		getline(cin, str);
		for (int i = 0; i < str.size(); i++)
		{
			if (str[i] == 'H' && str[i + 1] == 'o' && str[i + 2] == 's' && str[i + 3] == 'h' && str[i + 4] == 'i' && str[i + 5] == 'n' && str[i + 6] == 'o')
			{
				str[i + 6] = 'a';
			}
		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1200
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        long inpt = long.Parse(Reader.ReadLine());

        StringBuilder ans = new StringBuilder();
        ans.AppendLine("1");
        long currentNum = 1;
        for (int i = 1; i < inpt; i++) {
            currentNum = GetNum(++currentNum);
            ans.AppendLine(currentNum.ToString());
        }
        Console.Write(ans.ToString());
    }

    private long GetNum(long baseNum) {
        string num = baseNum.ToString();
        int keta = num.Length;

        long maxBunbo = (keta) * 9;
        long maxBunsi = long.Parse("9".PadRight(keta, '9'));
        List<long> bunbo = new List<long>();
        List<long> bunsi = new List<long>();
        for (int i = 0; i <= keta; i++) {
            string tmp = num.Substring(0, num.Length - i) + string.Empty.PadLeft(i, '9');
            long bo = tmp.Select(a => int.Parse(a.ToString())).Sum();
            long si = long.Parse(tmp);
            while (bunbo.Count > 0 && (si * bunbo.Last()) < (bunsi.Last() * bo))
            {
                bunbo.RemoveAt(bunbo.Count - 1);
                bunsi.RemoveAt(bunsi.Count - 1);
            }
            if(si*maxBunbo <= maxBunsi*bo) {
                bunbo.Add(bo);
                bunsi.Add(si);
            }
        }
        return bunsi.First();
    }


    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"
 
 
40
 
 
";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13464
#include <bits/stdc++.h>
#define gc getchar()
using namespace std;
typedef long long ll;
const int N=609;
const int A=29;
const int mod=998244353;
int n,a[N][N],b[N],c[N],ans,P[N];
char str[N];
int read()
{
	int x=1;
	char ch;
	while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
	int s=ch-'0';
	while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
	return s*x;
}
bool check(int x,int y)
{
	for (int i=1;i<=n;i++)
		if (b[i+y-1]!=c[x+i-1]) return 0;
	return 1;
}
int main()
{
	P[0]=1;
	for (int i=1;i<N;i++) P[i]=(ll)P[i-1]*A%mod;
	n=read();
	for (int i=1;i<=n;i++)
	{
		scanf("%s",str+1);
		for (int j=1;j<=n;j++)
			a[i][j]=str[j]-'a'+1;
	}
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++) a[i][j+n]=a[i][j],a[i+n][j]=a[i][j],a[i+n][j+n]=a[i][j];
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=2*n;j++)
		{
			b[j]=0;
			for (int k=i;k<i+n;k++)
				b[j]=((ll)b[j]*A+a[k][j])%mod;
		}
		for (int j=i;j<i+n;j++)
		{
			c[j]=0;
			for (int k=1;k<=n;k++)
				c[j]=((ll)c[j]*A+a[j][k])%mod;
		}
		for (int j=1;j<=n;j++)
		{
			if (check(i,j)) ans++;
			for (int k=i;k<i+n;k++)
				c[k]=((ll)(c[k]-(ll)a[k][j]*P[n-1]%mod+mod)*A+a[k][j+n])%mod;
		}
	}
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
 
#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    ll n, a, b;
    cin >> n >> a >> b;

    cout << a * (n / (a + b)) + min(n % (a + b), a) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(void){
  int a,b,c,k,m;
  
  scanf("%d%d%d%d", &a, &b, &c, &k);
  m = a>b?a:b;
  m = c>m?c:m;
  printf("%d\n",a+b+c-m+(m<<k));
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200000;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const int MOD = 1000000007;

int dx4[4]={1,0,-1,0};
int dy4[4]={0,1,0,-1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

ll gcd(ll a, ll b)
{
	if (b == 0) return a;
	return gcd(b, a%b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

void solve(void){
	int N;
	cin >> N;
	ll ans = 1;
	rep(N, i)
	{
		ll x;
		cin >> x;
		ans = lcm(ans, x);
	}

	cout << ans << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <set>
#include <numeric>
#define rep(i,n) for (int i=0; i < (n); ++i)
#define all(a) a.begin(), a.end()
using ll = long long;
using namespace std;



int main(){
  int a,b,c,d; cin >> a >> b >> c >> d;
  while (a > 0 && c >0)
  {
    c -= b;
    if (c <= 0) break;
    a -= d;
  }
  if (a>c) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;

}


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

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

int x;cin>>x;
if(x>=30){
  puts("Yes");
}else {
  puts("No");

}
  
  return 0;
}


Measured memory_bytes: 3612
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x = "";
        while(sc.hasNextLine()){
            x += sc.nextLine().toLowerCase();
        }

        sc.close();

        char y;
        char z ='a';
        int n[] = new int[26];
        for(int i = 0; i < x.length(); i++){
            y = x.charAt(i);
            for(int j = 0; j < 26; j++){
                if(z + j == y){
                    n[j] += 1;
                }
            }
        }

        for(int k = 0; k < 26; k++){
            System.out.printf("%c : %d\n", (char)(z + k), n[k]);
        }
    }
}


Measured memory_bytes: 26292
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#define rep(index,num) for(int index=0;index<num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-15
typedef long long ll;
using namespace std;
typedef pair<int,int> pint;
int main(){
	string S;
	ll K;
	char kmojime;
	scan(S);scan(K);
	for(ll i=0;i<K&&i<S.size();i++){
		if(S[i]!='1'){
			kmojime=S[i];
			break;
		}
		if(i==K-1||i==S.size()-1){
			kmojime='1';
			break;
		}
	}
	prin(kmojime);
	return 0;
}


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

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

    int sum = 0;
    rep(i,0,M) {
        int A; cin >> A;
        sum += A;
    }

    cout << max(N - sum, -1) << endl;

    return 0;
}


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



void solve(){
    
    int n, x, t; cin >> n >> x >> t;
    cout << (n + x - 1) / x * t << '\n';
    
}


int main(){
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false); cin.tie(0);

    int t = 1;
    // cin >> t;


    for(int i = 1; i <= t; i++){
        // cout << "Case #" << i << ": ";

        solve();

    }
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int N;
vector<int> P;
int main() {
	cin >> N;
	P.resize(N);
	for (auto& x : P) { cin >> x; -- x; }
	vector<int> a(N+1, 1);
	vector<int> b(N+1, -1);
	a[0] = 0;
	b[0] = N+1;
	for (int i = 0; i < N; ++ i) {
		b[1] += N-i;
		b[P[i]+1] -= N-i;
		a[P[i]+2] += N-i;
	}
	int aa = a[0], bb = b[0];
	for (int i = 0; i < N; ++ i) {
		aa += a[i+1];
		if (i) cout << " ";
		cout << aa;
	}
	cout << endl;
	for (int i = 0; i < N; ++ i) {
		bb += b[i+1];
		if (i) cout << " ";
		cout << bb;
	}
	cout << endl;
}


Measured memory_bytes: 1024
n,m = map(int,input().split())
a = [0] + list(map(int,input().split()))
dic = {0:1}
for i in range(1,n+1):
    a[i] += a[i-1]
    if a[i]%m in dic:
        dic[a[i]%m] += 1
    else:
        dic[a[i]%m] = 1
ans = 0
for key in dic:
    ans += dic[key]*(dic[key]-1)//2
print(ans)

Measured memory_bytes: 14408
n = int(input())
a = [int(i) for i in input().split()]
ans = []
x1 = 0
for i in range(n):
    x1 += a[i] * (-1)**i
ans.append(x1)
for i in range(n-1):
    x1 = (a[i] - (x1//2))*2
    ans.append(x1)
print(*ans)


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

int main() {
  int n;
  cin>>n;
  vector<vector<int>> f(9,vector<int>(9));
  
  for(int x = 1;x <= n;x++){
    int b = x%10;
    if(b == 0) continue;
    string xs = to_string(x);
    int a = xs[0] - '0';
    a--; b--;
    f[a][b]++;
  }

  int ans = 0;
  rep(i,9){
    rep(j,9){
      ans += f[i][j] * f[j][i];
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();
    let l: Vec<usize> = (0..n).map(|_| iterator.next().unwrap().parse().unwrap()).collect();

    let mut ans: usize = 0;
    for i in 0..n {
        for j in 0..n {
            for k in 0..n {
                if i >= j || j >= k {
                    continue;
                }
                if l[i] == l[j] || l[j] == l[k] || l[k] == l[i] {
                    continue;
                }
                if l[i] < l[j] + l[k] && l[j] < l[k] + l[i] && l[k] < l[i] + l[j] {
                    ans += 1;
                }
            }
        }
    }
    ans.to_string()
}


Measured memory_bytes: 2128
n = int(input())
arr = []
for i in range(n):
    arr.append(int(input())-1)
now = 0
c = 0
while True:
    if now == 1:
        print(c)
        break
    if c >= n:
        print(-1)
        break
    c += 1
    now = arr[now]

Measured memory_bytes: 12916
import java.util.*;
import java.io.*;
import java.math.*;
 
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // for(int i=0; i<n; i++) {a[i]=sc.nextInt();}
        int n=sc.nextInt();
        int m=sc.nextInt();
        int d[] = new int[n];

        for(int i=0,a,b,x,y; i<m; i++) {
            a=sc.nextInt()-1;
            b=sc.nextInt()-1;
            x=min(a,b); y=max(a,b);
            if(x==0)d[y]++;
            if(y==n-1)d[x]++;
        }
        String ans="IMPOSSIBLE";
        for(int i=0; i<n; i++) {
            if(d[i]>1){
                ans="POSSIBLE";
                break;
            }
        }

        out.println(ans);
        out.flush();
    }
    
    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }
     
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }
    
    static boolean bit(long x,int k){
        // weather k-th bit (from right) be one or zero
        return  ( 0 < ( (x>>k) & 1 )  )  ? true:false;
    }    
}

class P implements Comparable<P>{
        int id, d;
        P(int  id, int d) {
            this.id=id;
            this.d=d;
        } 
          
        public int compareTo(P p){
            return d-p.d; //descend
        }
    }

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}

Measured memory_bytes: 46776
#include<stdio.h>
int main(){
    int count[128]={0};
    char ch;
    while(scanf("%c",&ch)!= EOF){
        count[ch]++;
        }
    for (char c='a';c<='z';c++){
        printf("%c : %d\n",c,count[c]+count[c-32]);
    }
}


Measured memory_bytes: 2100
N, L = map(int, input().split())

Taste = []
for i in range(N):
    Taste.append(L + i)

Taste.sort()

if 0 in Taste:
    ans = sum(Taste)
    print(ans)
    exit(0)


T_max = sum(Taste)
T_sum1 = sum(Taste[1:])
T_sum2 = sum(Taste[:-1])
if abs(T_max - T_sum1) < abs(T_max - T_sum2):
    ans = T_sum1
else:
    ans = T_sum2

print(ans)


Measured memory_bytes: 3064
n=int(input())
A=[int(i) for i in input().split()]
r=[0 for i in range(n)]
l=[0 for i in range(n)]

for i in range(n):
    if A[i]+i<n:
        r[A[i]+i]+=1
    if i-A[i]>=0:
        l[i-A[i]]+=1

ans=0
for i in range(n):
    ans+=r[i]*l[i]
print(ans)

Measured memory_bytes: 32248
#include<bits/stdc++.h>
#define maxn 1005
using namespace std;
int read(){
	int x=0,c;while(!isdigit(c=getchar()));
	while(x=x*10+c-'0',isdigit(c=getchar()));
	return x;	
}
int a[maxn][maxn],d[maxn][maxn],ans=1e9,n,m,c[3][maxn*maxn];
int calc(int tmp,int C){
	int res=0;
	for(int i=1;i<=c[tmp][0];i++)
		res+=d[c[tmp][i]][C];
	return res;
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++)	
		for(int j=1;j<=m;j++)
		d[i][j]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)a[i][j]=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++){
			int tmp=(i+j)%3;
			c[tmp][++c[tmp][0]]=a[i][j];
		}
	for(int i=1,tmp1=0;i<=m;i++,tmp1=0){
		tmp1=calc(0,i);if(tmp1>=ans)continue;
		for(int j=1,tmp2;j<=m;j++)
			if(i!=j){
				tmp2=calc(1,j);if(tmp2+tmp1>=ans)continue;
				for(int k=1,tmp3;k<=m;k++)if(i!=k&&j!=k){
						tmp3=calc(2,k);
						ans=min(ans,tmp1+tmp2+tmp3);
					}
			}
		}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 14848
Module B
    Sub Main(ByVal args() As String)
        Dim arr1() As String = Split(Console.ReadLine())
        Dim arr2() As String = Split(Console.ReadLine())
        Dim arr3() As String = Split(Console.ReadLine())
        Dim bingo(,) As Integer = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}
        Dim n As Integer = Integer.Parse(Console.ReadLine())
        Dim a1, a2, a3, a4, a5, a6, a7, a8 As Integer

        For i As Integer = 1 To n
            Select Case Console.ReadLine()
                Case arr1(0)
                    bingo(0, 0) = 1
                Case arr1(1)
                    bingo(0, 1) = 1
                Case arr1(2)
                    bingo(0, 2) = 1
                Case arr2(0)
                    bingo(1, 0) = 1
                Case arr2(1)
                    bingo(1, 1) = 1
                Case arr2(2)
                    bingo(1, 2) = 1
                Case arr3(0)
                    bingo(2, 0) = 1
                Case arr3(1)
                    bingo(2, 1) = 1
                Case arr3(2)
                    bingo(2, 2) = 1
            End Select
        Next

        a1 = bingo(0, 0) + bingo(0, 1) + bingo(0, 2)
        a2 = bingo(1, 0) + bingo(1, 1) + bingo(1, 2)
        a3 = bingo(2, 0) + bingo(2, 1) + bingo(2, 2)

        a4 = bingo(0, 0) + bingo(1, 1) + bingo(2, 2)

        a5 = bingo(0, 2) + bingo(1, 2) + bingo(2, 2)
        a6 = bingo(0, 1) + bingo(1, 1) + bingo(2, 1)
        a7 = bingo(0, 0) + bingo(1, 0) + bingo(2, 0)

        a8 = bingo(2, 0) + bingo(1, 1) + bingo(0, 2)

        Dim ans() As Integer = New Integer(7) {a1, a2, a3, a4, a5, a6, a7, a8}

        If Array.IndexOf(ans, 3) <> -1 Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("No")
        End If
    End Sub
End Module

Measured memory_bytes: 22352
#include<bits/stdc++.h>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
const int N=1e5+5, INF=1e9;
using namespace std;
int q, cnt[2][2][N]; //string, letter, index
string s[2];
signed main()
{
    cin >> s[0] >> s[1];
    int l[] = {s[0].length(), s[1].length()};
    for(int i = 0; i < 2; i++)
    {
        for(int j = 0; j < 2; j++)
        {
            cnt[i][j][0]=0;
        }
    }
    for(int sn = 0; sn < 2; sn++)
    {
        for(int i = 1; i <= l[sn]; i++)
        {
            for(int j = 0; j < 2; j++)
            {
                cnt[sn][j][i] = cnt[sn][j][i-1] + (s[sn][i-1] == ('A'+j));
            }
        }
    }
    cin >> q;
    for(int i = 0; i < q; i++)
    {
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        int tot1 = cnt[0][0][b] - cnt[0][0][a-1];
        tot1 += 2*(cnt[0][1][b] - cnt[0][1][a-1]); 
        int tot2 = cnt[1][0][d] - cnt[1][0][c-1];
        tot2 += 2*(cnt[1][1][d] - cnt[1][1][c-1]);
        if(tot1%3 == tot2%3)
        {
            cout << "YES\n";
        } 
        else
        {
            cout << "NO\n";
        }
        
    }
}

Measured memory_bytes: 2432
import sys
import bisect
input = sys.stdin.readline
N, M = map(int, input().split())
p_list = [[] for _ in [0]*(N+1)]
q_list = []
for _ in [0]*M:
    p,y = map(int, input().split())
    q_list.append((p,y))
    p_list[p].append(y)
p_list = [sorted(y_list) for y_list in p_list]
for p,y in q_list:
    x = bisect.bisect_left(p_list[p],y)
    ans = "%06d%06d"%(p,x+1)
    print(ans)

Measured memory_bytes: 74160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e9 + 5;
#define INF 100000000000
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338;
const ll MAXN = 1e18;



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	char a,b;
	cin >> a >> b;
	int suma = a-'A';
	int ama = b-'A';
	if(suma > ama){
		cout << ">" << endl;
	}else if(suma < ama){
		cout << "<" << endl;
	}else{
		cout << "=" << endl;
	}
	return 0;
}



Measured memory_bytes: 3608
from collections import defaultdict

def answer():
    n, p = map(int, input().split())
    s = input()
    m = defaultdict(int)
    ans = 0
    if p == 2 or p == 5:
        for i, ss in enumerate(s):
            if int(ss) % p == 0:
                ans += i + 1
        return ans
    sss = 0
    for i, ss in enumerate(s[::-1]):
        sss = (sss + pow(10, i, p) * int(ss)) % p
        m[sss] += 1
    m[0] += 1
    for i in range(p):
        if m[i] >= 2:
            ans += m[i] * (m[i] - 1) // 2
    return ans

print(answer())




Measured memory_bytes: 4580
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, ab: [[usize; 2]; n]);

    let mut count = 0;

    for v in ab.iter().rev() {
        count += (v[1] - (count + v[0]) % v[1]) % v[1];
    }

    println!("{}", count);
}


Measured memory_bytes: 9580
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,l,n) for(size_t i=l; i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using mii = map<int,int>;
using pii = pair<int,int>;
using ti3 = tuple<int,int,int>;

int main(){
  ll n; cin>>n;
  vector<pii> s(n);
  REP(i,n){
    ll tmp; cin>>tmp;
    s[i] = make_pair(tmp,i+1);
  }
  sort(s.begin(),s.end());
  REP(i,n){
    cout<<s[i].second<<" ";  
  }
}

Measured memory_bytes: 1536
// Problem : C - XYZ Triplets
// Contest : AtCoder - AIsing Programming Contest 2020
// URL : https://atcoder.jp/contests/aising2020/tasks/aising2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
//int inf = 4e18;
const int N = 1e4+5;

int give(int x,int y,int z)
{
	return (x*x+y*y+z*z+x*y+y*z+z*x);
}		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		vector<int> v;
		for(int i=1;i<=100;++i)
		{
			for(int j=1;j<=100;++j)
			{
				for(int k=1;k<=100;++k)
				{
					int xxx = give(i,j,k);
					if(xxx<=10000)
					v.pb(give(i,j,k));
				}
			}
		}
		int mp[N] = {};
		for(int i:v)
		mp[i]++;
		for(int i=1;i<=n;++i)
		cout<<mp[i]<<"\n";		
    }
    return 0;
}


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

using namespace std;

int gcd(int a, int b)
{
    return (a % b == 0 ? b : gcd(max(b, a % b) , min(b, a % b)));
}

int main()
{
  int n, m; cin >> n >> m;
  cout << gcd(max(n, m), min(n, m)) << endl;
  return 0;
}



Measured memory_bytes: 3076
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
    int n,k,c;
    string s;
    set<int>ans;
    vector<int>init;
    cin >>n>>k>>c>>s;
    vector<int> patt;
    int at=0;
    vector<int>sum(n,0);
    for(int i=0;i<s.size();i++){
        if(i!=0){
            sum[i]+=sum[i-1];
        }
        if(s[i]=='o'){
            sum[i]++;
        }
   //  clog<<sum[i]<<" ";
    }
 //   clog<<endl;
    for(at=0;patt.size()!=k;at++){
        if(s[at]=='o'){
            ans.insert(at);
            patt.pb(at);
         
         //   clog<<at<<"  ";
            at += c ;
        }
        
       
    }
    patt.pb(n);
 
    int will=n;
    
    for (int i = patt.size() - 2; i >= 0; i--)
    {
        if (i == patt.size() - 2)
        {
           //clog << "!" << (sum[patt[i]] != sum[n - 1]) << " ";
            //   clog << "!" << (sum[patt[i]] )<<" "<<( sum[n-1]) << " ";
            if (sum[patt[i]] != sum[n - 1])
            {
                ans.erase(patt[i]);

                for (int j = n - 1; j > patt[i]; j--)
                {
                    if (s[j] == 'o')
                    {
                        will = j;
                        patt[i] = j;
                   //     clog << i << " -> " << j << "   ";
                        break;
                    }
                }
            }
          //  clog << (ans.find(patt[i]) == ans.end()) << endl;
        }
        else
        {
         //   clog << "!" << (sum[patt[i]] )<<" "<<( sum[patt[i + 1] - c-1]) << " ";
            if (sum[patt[i]] != sum[patt[i + 1]-c-1]  )
            {
                ans.erase(patt[i]);
                for (int j = patt[i + 1] - c-1; j > patt[i]; j--)
                {
                    if (s[j] == 'o')
                    {
                        will = j;
                        patt[i] = j;
                //        clog << i << " -> " << j << "   ";
                        break;
                    }
                }
            }
         //   clog << (ans.find(patt[i]) == ans.end()) << endl;
        }
    }

  //  cout<<ans<<endl;
//  clog<<endl;
  for(auto itr=ans.begin();itr!=ans.end()--;itr++){
      cout<<(*itr)+1<<endl;
  }
}

Measured memory_bytes: 12664
#include<bits/stdc++.h>
#include<limits>
#define ll long long
#define F first
#define S second
#define pb push_back
#define oo (1LL<<63-1)
#define endl '\n'
#define si size()
#define all(v) v.begin(),v.end()
#define FASTIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define Matrix vector< vector < long long > >


using namespace std;

int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};

const long double Pi=acos(-1),e=2.718;
const int N=2e3+10,mod=1e9+7;

int main ()
{
    FASTIO
    ll n , k;
    cin >> n >> k;
    map<int,int> Map;
    for(int i=0;i<k;i++){
        ll d;
        cin >> d;
        for(int j=0;j<d;j++){
            ll a;
            cin >> a;
            Map[a];
        }
    }
    cout << n-Map.si << endl;
    return 0;
}
/**

*/


Measured memory_bytes: 3672
#include<stdio.h>

#define N 45
int f[N];
int main(){
  int i,j,n;
  scanf("%d",&n);
  for(i=0;i<=n;i++){
    if(i==0 ||i==1){
      f[i]=1;
    }
    else f[i]=f[i-1]+f[i-2];
  }
  printf("%d\n",f[n]);


  return 0;
}

Measured memory_bytes: 596
#include<iostream>
using namespace std;
int a, b, c, d, e; char f;
int main() {
	while (cin >> a >> f >> b >> f >> c) {
		if (a*a + b*b == c*c) { d++; }
		if (a == b) { e++; }
	}
	cout << d << endl << e << endl;
}

Measured memory_bytes: 1156
n = gets.to_i
a = gets.split.map(&:to_i)

c = [0,0,0,0]
a.each {|e| c[e % 4] += 1}

if c[0] * 2 + 1 >= n
    puts "Yes"
elsif c[0] * 2 + c[2] >= n
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 8452
import java.io.*;
public class Main {
    public static void main(String[] args){
        int[] H;
        int[] W;
        int i,j,k,l;
        H = new int[1000];
        W = new int[1000];
       BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try{
            k=0;
            while(true){
            String tate=reader.readLine();
            String[] count1 = tate.split(" ");
            H[k] = Integer.parseInt(count1[0]);
            W[k] = Integer.parseInt(count1[1]);
            if(H[k]==0 && W[k]==0){
                break;
            }
            k++;
            }
            for(l=0;l<k;l++){
                for(i=0;i<H[l];i++){
                    if(i>0){
                        System.out.print("\n");
                    }
                    for(j=0;j<W[l];j++){
                        System.out.print("#");
                }
            }
            System.out.println("\n");
        }
        }catch(IOException e){
            System.out.println(e);
        }catch(NumberFormatException e){
            System.out.println("wrong");
        }
    }
}



Measured memory_bytes: 31468
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ll n,k,ans1=0,ans2=0;
    cin>>n>>k;
    if(k%2==1){
        for(int i=1;i<=n;i++){
            if(i%k==0)ans1++;
        }
    }
    else{
        for(int i=1;i<=n;i++){
            if(i%k==0)ans1++;
            if(i%k==k/2)ans2++;
        }
    }
    cout<<ans1*ans1*ans1+ans2*ans2*ans2<<endl;

}

Measured memory_bytes: 256
//url:
//problem name: Brick Break

#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); ++i)
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;}
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<long long,long long>;
using veci = vector<int>;
using vecl = vector<long>;
using vecveci = vector<vector<int>>;
using vecvecl = vector<vector<long long>>;

int main() {
    int N; cin >> N;
    veci L(N);
    REP(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    int ans = 0;
    REP(i,N-2) {
        for(int j = i + 1; j < N-1; j++) {
            for(int k = j + 1; k < N; k++) {
                //cout << L[i] << " " << L[j] << " " << L[k] << endl;
                if(L[k] < L[i] + L[j]) ans++;
                else break;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
#define int long long int
using namespace std;
int exp(int a,int x){
      if(x==0)return 1;
      if(x%2)return a*exp(a,x-1)%modulo;
      int t=exp(a,x/2);
      return t*t%modulo;
}
vector<int> fact(300000,1);
vector<int> inv(300000,1);
inline int comb(int n,int r){
      return fact[n]*inv[r]%modulo*inv[n-r]%modulo;
}
int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
   //   freopen("q.gir","r",stdin);
   //   freopen("q.cik","w",stdout);
      int n,m,k;
      cin>>n>>m>>k;n--,m--;
      for(int i=1;i<fact.size();i++)fact[i]=fact[i-1]*i%modulo;
      for(int i=0;i<fact.size();i++)inv[i]=exp(fact[i],modulo-2);
      int A=comb(n+m,n);
      map<int,set<int>>Q;
      for(int i=0;i<k;i++){
            int x,y;
            cin>>x>>y;x--,y--;
            Q[x].insert(y);
      }
      vector<ii>arr;
      for(map<int,set<int>>::iterator itr=Q.begin();itr!=Q.end();itr++){
            for(set<int>::iterator it=itr->second.begin();it!=itr->second.end();it++){
                  arr.pb({itr->first,*it});
            }
      }
      vector<int> val(k,0);
      for(int i=0;i<k;i++){
            int x=arr[i].first,y=arr[i].second;
            int B=comb(x+y,x);
            for(int j=0;j<i;j++){
                  if(arr[j].second>y)continue;
                  B=(B+modulo-val[j]*comb(x+y-arr[j].first-arr[j].second,x-arr[j].first)%modulo)%modulo;
            }
            val[i]=B;
            A=(A+modulo-B*comb(n+m-x-y,n-x)%modulo)%modulo;
      }
      cout<<A;
}


Measured memory_bytes: 5504
#include<bits/stdc++.h>
#define ll long long int
#define vi vector<int>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define lop(i,a,b) for(ll i=a;i<b;i++)
using namespace std;

void func(){
    char a;
    cin>>a;
    if(a<97)cout<<"A"<<endl;
    else cout<<"a"<<endl;
}

int main(){
    fastio;
    int t=1;
    //cin>>t;
    while(t--){
        func();
    }
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;
#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(v, n) sort(v, v+n)
#define VSORT(v) sort(v.begin(), v.end())
#define REP(i, n) for(int i = 0;i < n;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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 999999999
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(){
    int N;
    VI V(N);
    VI C(N);
    VI R(N);
    int count=0;
    cin >> N;
    REP(i,N){
        cin >> V[i];
    }
    REP(i,N){
        cin >> C[i];
        R[i]=V[i]-C[i];
    }
    REP(i,N){
        if(R[i]>0){
            count+=R[i];
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A,*B;
  int C[VMAX+1];
  int n,i,j;
  scanf("%d",&n);
  A=malloc(sizeof(short)*n+1);
  B=malloc(sizeof(short)*n+1);

  for(i=0;i<=VMAX;i++)C[i]=0;
  for(i=0;i<n;i++){
    scanf("%hu",&A[i+1]);
    C[A[i+1]]++;
  }
  for(i=1;i<=VMAX;i++)C[i]=C[i]+C[i-1];
  for(j=1;j<=n;j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i=1;i<=n;i++){
    if(i>1)printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  return 0;
}



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

int main() {
  ll N, X, M;
  cin >> N >> X >> M;
  vector<bool> f(M,false);
  vector<ll> calc(M);
  calc[0] = X;
  f[X] = true;
  ll now = 0;
  for (now = 1; now < min(M, N); now++) {
    calc[now] = calc[now-1] * calc[now-1] % M;
    if (f[calc[now]]) break;
    else f[calc[now]] = true;
  }
  ll ans = 0;
  if (now != (M-1)) {
    ll loop = 0;
    rep(i,now) {
      if (calc[i] == calc[now]) {
        loop = i;
        break;
      }
    }
    ll temp = 0;
    for (ll i = loop; i < now; i++){
      temp += calc[i];
    }
    ll x = (N - loop)/(now-loop);
    ans += x*temp;
    rep(i, loop) ans += calc[i];
    ll y = (N - loop) % (now - loop);
    for (ll i = loop; i < loop+y; i++) ans += calc[i];
  } else{
    rep(i,N) ans += calc[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4044
#include<bits/stdc++.h>
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> set_t;
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define SUM(v) accumulate(v.begin(),v.end(),lli(0))
#define rev(n,d) for(int i=n;i>=d;i--)
#define FOR0(n) for(int i=0;i<n;i++)
#define FOR(a,n) for(int i=a;i<n;i++)
#define FORQ(a,n) for(int i=a;i<=n;i++)
#define inf 1000000009
#define inff 0x3f3f3f3f
#define sz(a) int((a).size())
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define endl "\n"
#define mod 1000000007
#define mem(ar,x) memset(ar,x,sizeof ar)
#define present(container, element) (container.find(element) != container.end())
#define max3(a,b,c) return (lli(a)>lli(b)?(lli(a)>lli(c)?a:c):(lli(b)>lli(c)?b:c))
#define max4(a,b,c,d) return (max3(a,b,c)>lli(d)?(max3(a,b,c)):d)
#define min3(a,b,c) return (lli(a)<lli(b)?(lli(a)<lli(c)?a:c):(lli(b)<lli(c)?b:c))
#define min4(a,b,c,d) return (max3(a,b,c)<lli(d)?(max3(a,b,c)):d)
typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<int,pii>ppii;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<pii>vpii;
const int N=78;
int dr8[]={0,0,1,-1,1,1,-1,-1};
int dc8[]={1,-1,0,0,-1,1,-1,1};
int dr4[]={0,1,-1,0};
int dc4[]={1,0,0,-1};
int dp[1<<22];
int main(){
	fast
	int n;
	cin>>n;
	int a[n][n];
	dp[0]=1;
	FOR0(n)
		for(int j=0;j<n;j++) cin>>a[i][j];	
	//for(int i=0;i<n;i++){
		for(int mask=0;mask<(1<<n);mask++){
			int i=__builtin_popcount(mask);
			for(int k=0;k<n;k++){
				if(!(mask&(1<<k))&&a[i][k]){
					dp[mask^(1<<k)]=(1ll*dp[mask^(1<<k)]+dp[mask])%mod;
				}
			}
		}
	//}
	cout<<dp[(1<<n)-1];
}



Measured memory_bytes: 10624
#include <iostream>

using namespace std;

typedef long long int64;

constexpr int64 mod = 1000000007;

int64 fac(int64 n) {
    int64 res = 1;
    for(int64 i = 1;i <= n;i++) res = res * i % mod;
    return res;
}

int main(int argc, const char * argv[]) {
    int64 n,m;
    cin >> n >> m;
    if(abs(n-m) == 0)
        cout << fac(n) * fac(m) *2 % mod;
    else if(abs(n-m) == 1)
        cout << fac(n) * fac(m) % mod;
    else
        cout << 0;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
  int x[5];
  for(int i = 0; i < 5; i++) {
    cin >> x[i];
  }

  for(int i = 0; i < 5; i++) {
    if(x[i] == 0) { cout << i + 1; return 0; }
  }
  return 0;
  }

Measured memory_bytes: 3524
n = int(input())

def divisor(n):
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table


def tester(n, k):
    if k == 1:
        return False

    temp = n
    while temp % k == 0:
        temp /= k

    if temp % k == 1:
        return True
    else:
        return False

answer = []
for i in (divisor(n - 1) + divisor(n)):
    if tester(n, i):
        answer.append(i)

print(len(answer))

Measured memory_bytes: 39920
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <cstdio>

using namespace std;

int main(){
  int n, k, x, tot;
  tot = 0;
  cin >> n;
  cin >> k;
  for (int i=0;i<n;i++) {
    cin >> x;
    int d = x > k-x?k-x:x;
    tot += d;
  }
  cout << 2*tot << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define INF 0x3f3f3f3f
#define lowbit(x) x & -x
#define lson root<<1,l,mid
#define rson root<<1|1,mid+1,r
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int N=2e5+5;
char mp[1005][1005];
int num[1005][1005],cnt;
bool vis[1005][1005];
struct node{
    int x,y;
    int dis;
    friend bool operator < (node a, node b)    
    {    
        return a.dis > b.dis;    
    }  
};
priority_queue<node>que;

int d[][2]={-1,0,1,0,0,-1,0,1};
int n,m,stx,sty,edx,edy;
void dfs(int x,int y){
    num[x][y]=cnt;
    for(int i=0;i<4;i++){
        int tx=x+d[i][0],ty=y+d[i][1];
        if(tx>=1 && tx<=n && ty>=1 && ty<=m && !num[tx][ty] && mp[tx][ty]=='.')
            dfs(tx,ty);
    }
}

int main(){
#ifdef Mizp
    freopen("in.txt","r",stdin);
#endif
    
    scanf("%d%d%d%d%d%d",&n,&m,&stx,&sty,&edx,&edy);
    for(int i=1;i<=n;i++){
        scanf("%s",mp[i]+1);
    }
    int ans=1e9;
    cnt=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            if(mp[i][j]=='.' && num[i][j]==0){
                cnt++;
                dfs(i,j);
            }   
        }
    }
    node tmp;
    tmp.x=stx,tmp.y=sty,tmp.dis=0;
    que.push(tmp);
    while(!que.empty()){
        int tx=que.top().x,ty=que.top().y,dis=que.top().dis;
        que.pop();
        if(vis[tx][ty])
            continue;
        vis[tx][ty]=1;
        if(tx==edx && ty==edy){
            ans=dis;
            break;
        }
        for(int i=max(1,tx-2);i<=min(n,tx+2);i++){
            for(int j=max(1,ty-2);j<=min(m,ty+2);j++){
                if(vis[i][j] || mp[i][j]=='#')
                    continue;
                tmp.dis=dis;
                if(num[i][j]!=num[tx][ty]){
                    tmp.dis+=1;
                }
                tmp.x=i,tmp.y=j;
                que.push(tmp);
            }
        }
    }
    if(!vis[edx][edy])
        puts("-1");
    else 
        printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 9916
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(t) t.begin(), t.end()
#define inrange(i, a, b) (((i)>= min((a), (b))) && ((i) <= max((a), (b))))
typedef vector<ll> vi;
#define fi first
#define se second
const ll inf = 9e18;
const ll mod = 1e9 + 7;

void print(ll a[], ll n){for(ll i=0;i<n;i++){cout<<a[i]<<" ";}cout<<"\n";}
ll power(ll x, ll y, ll M = inf){
    ll ans = 1;
    x %= M;
    while(y){
        if(y&1)
            ans = (x * ans) % M;

        x = (x * x) % M;
        y >>= 1;
    }
    return ans;
}
ll modInverse(ll n) {return power(n, mod-2, mod);}
inline ll mul(ll a, ll b){ return (a * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > mod) c -= mod; return c; }
inline ll divi(ll a, ll b){ return mul(a, modInverse(b)); }

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin>>n;
	cout<<2*3.1415*n;
	return 0;
}


Measured memory_bytes: 3808
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define inf 500000000
#define IOS ios_base::sync_with_stdio(0)
#define meM(y,a) memset(y,a,sizeof y)
#define sC(a) scanf("%d",&a)
#define alL(a) a.begin(),a.end()
#define prinT(a,sz)  cout<<a[0];for(int i=1;i<sz;i++)cout<<" "<<a[i];cout<<endl
#define ranD srand(chrono::steady_clock::now().time_since_epoch().count());
typedef pair<int,int>pi;
typedef pair<ll,ll>pll;
int fx[]={0,0,1,-1};
int fy[]={1,-1,0,0};
//int gx[]={0,0,1,1,1,-1,-1,-1};
//int gy[]={1,-1,0,1,-1,0,1,-1};
bool check(int n,int p){return (1<<p)&n;}
vector<string>v;
int dis[55][55];
int r,c;
void bfs(int x,int y)
{
    queue<pi> q;
    q.push({x,y});
    while(!q.empty())
    {
        pi top=q.front();
        q.pop();
        for(int k=0;k<4;k++)
        {
            int xx=top.ff+fx[k];
            int yy=top.ss+fy[k];
            if(xx>=0&&yy>=0&&xx<r&&yy<c)
            {
                if(dis[xx][yy]==0&&v[xx][yy]=='.')
                {
                    dis[xx][yy]=dis[top.ff][top.ss]+1;
                    q.push({xx,yy});
                }
            }
        }
    }
}
int main()
{
    IOS;
    dis[0][0]=1;
    cin>>r>>c;
    for(int i=0;i<r;i++)
    {
        string s;cin>>s;
        v.pb(s);
    }
    bfs(0,0);
    if(dis[r-1][c-1]==0)cout<<-1<<endl;
    else{
        int tot=0;
        for(int i=0;i<r;i++)
            for(int j=0;j<c;j++)if(v[i][j]=='.')tot++;
//        cout<<tot<<"  "<<dis[r-1][c-1]<<endl;
        cout<<tot-dis[r-1][c-1]<<endl;
    }
}








Measured memory_bytes: 256