akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		while(sc.hasNext()) {
			String str = sc.nextLine();
			pyramid(str);
		}

	}

	private static void pyramid(String str) {
		int[][] pyramid = new int[str.length()][str.length()];

			for (int i = 0; i < str.length(); i++) {
				pyramid[0][i] = str.charAt(i) - '0';
			}

			for (int i = 0; i < str.length() - 1; i++) {
				for (int j = 0; j < str.length() - 1; j++) {
					pyramid[i + 1][j] = ( pyramid[i][j] + pyramid[i][j + 1] ) % 10;
				}
			}
		System.out.println(pyramid[str.length() - 1][0]);
	}
}


Measured memory_bytes: 26040
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
using namespace std;


typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)



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

  vector<vector<int> > x(n, vector<int>(d));
  rep(i, n){
    rep(j, d){
      cin >> x[i][j];
    }
  }

  for(int i = 0; i < n; ++i){
    for(int j = i; j < n; ++j){
      double distance = 0;
      if(i == j)  continue;
      for(int k = 0; k < d; ++k){
        distance += pow(x[i][k] - x[j][k], 2);
      }
      distance = sqrt(distance);

      if(distance == (int)distance) ans++;


    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int a,b,k;
    cin>>a>>b>>k;
    for(int i=a;i<=b;i++){
        if(i<a+k)cout<<i<<endl;
        else if(b-k<i)cout<<i<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
	   const int MAX_V = 1000000;
	   int prime[MAX_V+1];
	   int main(){
	   	int i,k,v,m=2;
	   	for(i=m;i<=MAX_V;i++){
	   		prime[i]=1;
	   	}
	   	for(i=m;i*i<=MAX_V;i++){
	   		if(prime[i]){
	   			for(k=2*i;k<=MAX_V;k+=i){
	   				prime[k]=0;
	   			}
	   		}
	   	}
	   	while(scanf("%d",&v)!=EOF){
	   		if(v==0)break;
	   		for(i=v;i>=m;i--){
	   			if(prime[i]==1 && prime[i-2]==1){
	   				printf("%d %d\n",i-2,i);
	   				break;
	   			}
	  	   	}
	  	}
	   	return 0;
	  }

Measured memory_bytes: 6492
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [x,y] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  putStrLn $ if or [ 2 * 鶴 + 4 * 亀 == y | 鶴 <- [0..x], let 亀 = x - 鶴 ] then "Yes" else "No"


Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n;
	while (cin >> n, n)
	{
		vector<pii> v;
		REP(i, n)
		{
			int a, b; cin >> a >> b;
			v.emplace_back(a, b);
		}
		sort(ALL(v));
		int sum = 0;
		REP(i, n - 1) sum += v[i].first;
		if (sum >= v.back().first)
		{
			sum += v.back().first;
			REP(i, n) sum += v[i].second;
			cout << sum << endl;
		}
		else
		{
			int w = v.back().first - sum;
			vi t;
			REP(i, n - 1) t.push_back(v[i].second);
			vector<bool> dp(w + 1, false);
			dp[0] = true;
			int mx = 0;
			REP(i, n - 1)for (int j = w; j >= 0; j--)
			{
				if (dp[j] && j + t[i] <= w)
				{
					dp[j + t[i]] = true;
					chmax(mx, j + t[i]);
				}
			}
			int ans = v.back().first * 2;
			REP(i, n)
			{
				ans += v[i].second;
			}
			ans -= mx;
			cout << ans << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3152
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Anser(new ConsoleInput(Console.In, ' '));
        }

        public void Anser(ConsoleInput Input)
        {
            var inputData = Input.ReadIntArray(2);
            var favoriteData = new List<int>();
            
            for (int i = 0; i < inputData[0]; i++)
            {
                var favoAns = Input.ReadLine.Split(' ').Select(x => Convert.ToInt32(x)).ToList<int>();
                favoriteData.AddRange(favoAns.GetRange(1, favoAns.Count - 1).Distinct().ToList<int>());
            }

            var anserCount = 0;

            for (int i = 1; i <= inputData[1]; i++)
            {
                var favo = favoriteData.Count(x => x == i);

                if (favo == inputData[0])
                    anserCount++;
            }

            Console.WriteLine(anserCount);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader Stream;
        private char Separator = ' ';
        private Queue<string> InputStream;

        public ConsoleInput(System.IO.TextReader Stream, char Separator = ' ')
        {
            this.Separator = Separator;
            this.Stream = Stream;
            InputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (InputStream.Count != 0)
                {
                    return InputStream.Dequeue();
                }

                string[] splitStrs = Stream.ReadLine().Split(Separator);

                for (int i = 0; i < splitStrs.Length; ++i)
                {
                    InputStream.Enqueue(splitStrs[i]);
                }

                return InputStream.Dequeue();
            }
        }

        public string ReadLine { get { return Stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}

        public string[] ReadStrArray(long N) 
        { 
            var inputStrArray = new string[N];
            for (long i = 0; i < N; ++i)
            {
                inputStrArray[i] = Read;
            } 
            
            return inputStrArray;
        }

        public int[] ReadIntArray(long N) 
        { 
            var inputIntArray = new int[N];
            for (long i = 0; i < N; ++i)
            {
                inputIntArray[i] = ReadInt;
            }
           
            return inputIntArray;
        }

        public long[] ReadLongArray(long N) 
        { 
            var inputLongArray = new long[N];
            for (long i = 0; i < N; ++i)
            {
                inputLongArray[i] = ReadLong;
            }
            
            return inputLongArray;
        }
    }
}

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

public class Main {
  private static int solve(int n) {
    return 800 * n - 200 * (n / 15);
  }
  
  private static void execute(ContestReader reader, PrintWriter out) {
    int n = reader.nextInt();
    out.println(solve(n));
  }
  
  public static void main(String[] args) {
    ContestReader reader = new ContestReader(System.in);
    PrintWriter out = new PrintWriter(System.out);
    execute(reader, out);
    out.flush();
  }
}

class ContestReader {
  private BufferedReader reader;
  private StringTokenizer tokenizer;
  
  ContestReader(InputStream in) {
    reader = new BufferedReader(new InputStreamReader(in));
  }
  
  public String next() {
    while (tokenizer == null || !tokenizer.hasMoreTokens()) {
      try {
        tokenizer = new java.util.StringTokenizer(reader.readLine());
      } catch (Exception e) {
        throw new RuntimeException(e);
      }
    }
    return tokenizer.nextToken();
  }
  
  public int nextInt() {
    return Integer.parseInt(next());
  }
  
  public long nextLong() {
    return Long.parseLong(next());
  }
  
  public double nextDouble() {
    return Double.parseDouble(next());
  }
  
  public String[] next(int n) {
    String[] array = new String[n];
    for (int i = 0; i < n; i++) {
      array[i] = next();
    }
    return array;
  }
  
  public int[] nextInt(int n) {
    int[] array = new int[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextInt();
    }
    return array;
  }
  
  public long[] nextLong(int n) {
    long[] array = new long[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextLong();
    }
    return array;
  }
  
  public double[] nextDouble(int n) {
    double[] array = new double[n];
    for (int i = 0; i < n; i++) {
      array[i] = nextDouble();
    }
    return array;
  }
  
  public char[] nextCharArray() {
    return next().toCharArray();
  }
  
  public int[][] nextInt(int n, int m) {
    int[][] matrix = new int[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextInt();
      }
    }
    return matrix;
  }
  
  public long[][] nextLong(int n, int m) {
    long[][] matrix = new long[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextLong();
      }
    }
    return matrix;
  }
  
  public double[][] nextDouble(int n, int m) {
    double[][] matrix = new double[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        matrix[i][j] = nextDouble();
      }
    }
    return matrix;
  }
  
  public char[][] nextCharArray(int n) {
    char[][] matrix = new char[n][];
    for (int i = 0; i < n; i++) {
      matrix[i] = next().toCharArray();
    }
    return matrix;
  }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
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;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll n; cin >> n;
    vector<long long> vec(n);
    for(long long i = 0; i < n; i ++){
        cin >> vec[i];
    }

    ll tmp = vec[0];
    for(ll i = 1; i < n; i ++){
        tmp = tmp ^ vec[i];
    }

    rep(i, n){
        cout << (vec[i] ^ tmp) << " ";
    }
    br;


}

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
using namespace std;
int main()
{
	int A,B,C;
	cin>>A>>B;
	C=A-2*B;
	if(C<=0){
		cout<<"0"<<endl;
	}
	else{
		cout<<C<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll t, n, k;
int main()
{
    cin>>k;
    string s;
    cin>>s;
    ll i;
    ll x=s.size();
    for(i=0;i<min(x,k);i++)
        cout<<s[i];
    if(i<s.size())
        cout<<"...";

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
using P = pair<int,int>;
using pq = priority_queue<int>;
typedef long long ll;
typedef long double ld;
#define pi 3.14159265358979

int  main()
{
	string s; cin >> s;
	if (s[0] == s[2])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#define lp for(ll i=0;i<n;i++)
#define MN 200000
using namespace std;typedef long long ll;ll n, k, a[MN], f[MN];bool ps(ll t) {ll s=0;lp if(a[i]*f[i]>t)s+=a[i]-t/f[i];return s<=k;}int main(){cin>>n>>k;lp cin>>a[i];lp cin>>f[i];sort(a,a+n);sort(f,f+n,greater<>());ll r=0,l=10000000000000000;while(l-r){ll m=(r+l)/2;if(ps(m))l=m;else r=m+1;}cout<<r<<endl;}

Measured memory_bytes: 3328
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	iv, _ := strconv.Atoi(scanString())
	return iv
}

func scanString() string {
	sc.Scan()
	return sc.Text()
}

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 100001), 100001*100)
}

func main() {
	h, w := scanInt(), scanInt()
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			s := scanString()
			if s == "snuke" {
				fmt.Println(string('A'+j) + strconv.Itoa(i+1))
				return
			}
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    string a, b;
    cin >> a >> b;
    ll n = a.size();
    ll m = b.size();
    vector<vector<ll>>dp(n+1,vector<ll>(m+1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1]);
            if (a[i] == b[j]) {
                dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + 1);
            }
        }
    }
    ll t = n;
    ll v = m;
    string ans = "";
    for (int i = 0; i < n+m; i++) {
        if (t - 1 != -1 && dp[t][v] == dp[t - 1][v])t--;
        else if (v - 1 != -1 && dp[t][v] == dp[t][v-1])v--;
        else {
            t--;
            v--;
            i++;
            ans += a[t];
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 73664
n, a, b = map(int, input().split())
if a+b-1 > n or a*b < n:
	print(-1)
elif b == 1:
	print(*list(range(1, n+1)))
else:
	ans = list(range(n-a+1, n+1))
	num = b-1
	mod = n-a - (n-a)//(b-1) * (b-1)
	size1 = (n-a)//(b-1)
	size2 = size1 + 1
	mi = n-a
	for i in range(num):
		if i < num-mod:
			ans += list(range(mi - size1 + 1, mi + 1))
			mi = mi - size1
		else:
			ans += list(range(mi - size2 + 1, mi + 1))
			mi = mi - size2
	print(*ans)

Measured memory_bytes: 21820
S = input()
n = len(S)
ans = [0]*(n+1)
for i in range(n):
    if S[i]=='<':

        ans[i+1]=ans[i]+1
    # print(ans)
# print(ans)
for i in range(n-1,-1,-1):
    if S[i]==">":
        if ans[i]>ans[i+1]:
            continue
        else:
            ans[i]=ans[i+1]+1
    # print(ans)
res = 0
for i in range(n+1):
    res+=ans[i]
# print(ans)
print(res)

Measured memory_bytes: 23336
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>

using namespace std;
#define ll long long
#define pb push_back

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

  if(X==3 || X==5 || X==7) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
    string s;
    cin >> s;
    int k;
    cin >> k;

    int n = s.length();
    int m = k * n;

    string *t = new string[m];
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < k; j++) {
            t[i*k+j] = s.substr(i,j+1);
        }
    }

    sort(t, t+m);

    if (k == 1) {
        cout << t[0] << endl;
        return 0;
    }

    int c = 1;
    for (int i = 1; i < m; i++) {
        if (t[i - 1].compare(t[i]) != 0) {
            c++;
            if (c == k) {
                cout << t[i] << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1664
H,W = map(int,input().split())
a = [input() for _ in range(H)]
dp = [[0 for _ in range(W+1)] for __ in range(H+1)]
dp[1][0]=1
mod_numb = 1000000007
for h in range(1,H+1):
    for w in range(1,W+1):
        if a[h-1][w-1]=='#':
            continue
        else:
            dp[h][w] = (dp[h-1][w] + dp[h][w-1])%mod_numb
print(dp[H][W])

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

vector<pair<int,int> > e[100001];

int dp[100001];
long long int ans;
int n, cent;

bool ok;

void dfs(int x,int p){
	dp[x]=1;
	int msz = 0;
	for(auto z:e[x]){
		int it=z.first;
		if(it!=p){
			dfs(it,x);
			dp[x]+=dp[it];
			ans+= 2LL * z.second * min(dp[it], n-dp[it]); 
			if(dp[it]*2==n)	ok = true, ans-=z.second;
			msz=max(msz,dp[it]);
		}
	}
	msz=max(msz,n-dp[x]);
	if(msz * 2 <=n)
		cent=x;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	for(int i=1,u,v,w;i<n;i++)
		cin>>u>>v>>w,e[u].emplace_back(v,w),e[v].emplace_back(u,w);
	dfs(1,0);
	if(!ok){
		int z = 1e9;
		for(auto it:e[cent])
			z=min(z,it.second);
		ans-=z;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 12800
#include <bits/stdc++.h>
#define ll  long long
#define ull unsigned long long  
using namespace std;
#define  inf 1e6+18
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mod 1000000007
#define  f1(i,n) for(i=1;i<=n;i++)
#define f0(i,n)  for(i=0;i<n;i++)
#define w(x)   while(x--)
const int maxn=500001;
#define  pq priority_queue
#define  ff first
#define  ss second 
#define pb  push_back
#define lb lower_bound

ll k1=0;
bool comp(pair<ll,ll>a,pair<ll,ll>b)
{
	k1=max(k1,abs(a.ff-b.ff)+abs(a.ss-b.ss));
	if(a.ff>b.ff)
		return 1;

	if(a.ff==b.ff&&a.ss>b.ss)
		return 1;
	return 0;
}
int dx[]={1,-1};
int dy[]={1,-1};
int main()
{
	fastio;
	int t;
	ll i,j,k,n,m,l;
	cin>>n;
	
	n=n^1;
	cout<<n;
}
//Lordvishnu@almighty

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

    static Scanner stdIn = new Scanner(System.in);
    public static void main(String[] args) {
        String s = stdIn.next();
        char[] sc = s.toCharArray();

        int first = (sc[0]-'0')*10 + (sc[1]-'0');
        int second = (sc[2]-'0')*10 + (sc[3]-'0');

        boolean firstIsYY = false;
        boolean firstIsMM = false;
        boolean secondIsYY = false;
        boolean secondIsMM = false;

        if(1<=first && first <=12){
            firstIsMM = true;
        }
        if(0<= first && first <=99){
            firstIsYY = true;
        }

        if(1<=second && second <=12){
            secondIsMM = true;
        }
        if(0<= second && second <=99){
            secondIsYY = true;
        }

        if((firstIsYY && secondIsMM) && (firstIsMM && secondIsYY)){
            System.out.println("AMBIGUOUS");
        }else if(firstIsMM && secondIsYY){
            System.out.println("MMYY");
        }else if(firstIsYY && secondIsMM){
            System.out.println("YYMM");
        }else{
            System.out.println("NA");
        }

    }
}

Measured memory_bytes: 22612
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200000

struct Info{
	int x,y;
};

int N,table_X[2*NUM+1],table_Y[2*NUM+1];
Info info[101],curtain[4];
vector<int> X,Y;


void func(){

	X.clear();
	Y.clear();

	X.push_back(-BIG_NUM);
	X.push_back(BIG_NUM);
	Y.push_back(-BIG_NUM);
	Y.push_back(BIG_NUM);

	for(int i = 0; i < N; i++){
		scanf("%d %d",&info[i].x,&info[i].y);
		X.push_back(info[i].x);
		Y.push_back(info[i].y);
	}

	for(int i = 0; i < 4; i++){
		scanf("%d %d",&curtain[i].x,&curtain[i].y);
		X.push_back(curtain[i].x);
		Y.push_back(curtain[i].y);
	}

	sort(X.begin(),X.end());
	sort(Y.begin(),Y.end());

	X.erase(unique(X.begin(),X.end()),X.end());
	Y.erase(unique(Y.begin(),Y.end()),Y.end());

	for(int i = 1; i < X.size()-1; i++){
		table_X[X[i]+NUM] = i;
	}

	for(int i = 1; i < Y.size()-1; i++){
		table_Y[Y[i]+NUM] = i;
	}

	for(int i = 0; i < N; i++){
		info[i].x = table_X[info[i].x+NUM];
		info[i].y = table_Y[info[i].y+NUM];
	}

	info[N].x = info[0].x;
	info[N].y = info[0].y;

	int H = (int)Y.size(),W = (int)X.size();

	int calc_table[H][W];

	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			calc_table[row][col] = 0;
		}
	}

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

		if(info[i].x == info[i+1].x){

			if(info[i].y < info[i+1].y){

				for(int row = info[i].y; row < info[i+1].y; row++){
					calc_table[row][info[i].x]--;
				}
			}else{

				for(int row = info[i+1].y; row < info[i].y; row++){
					calc_table[row][info[i].x]++;
				}
			}
		}
	}

	for(int row = 0; row < H; row++){
		for(int col = 1; col < W; col++){
			calc_table[row][col] += calc_table[row][col-1];
		}
	}

	int min_row = BIG_NUM,max_row = -1,min_col = BIG_NUM,max_col = -1;

	for(int i = 0; i < 4; i++){
		curtain[i].x = table_X[curtain[i].x+NUM];
		min_col = min(min_col,curtain[i].x);
		max_col = max(max_col,curtain[i].x);

		curtain[i].y = table_Y[curtain[i].y+NUM];
		min_row = min(min_row,curtain[i].y);
		max_row = max(max_row,curtain[i].y);
	}

	for(int row = min_row; row < max_row; row++){
		for(int col = min_col; col < max_col; col++)calc_table[row][col]--;
	}

	ll ans = 0;
	for(int row = 0; row < H; row++){
		for(int col = 0; col < W; col++){
			if(calc_table[row][col] == 1){
				ans += (X[col+1]-X[col])*(Y[row+1]-Y[row]);
			}
		}
	}

	printf("%lld\n",ans);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3592
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	for (;;) {
		int N, A, B, C, X;
		cin >> N >> A >> B >> C >> X;
		if (N == 0) break;
		vector<int> Y(N);
		for (int i = 0; i < N; i++) cin >> Y[i];
		int cnt = -1;
		for (int i = 0; i < N; i++) {
			for (;;) {
				cnt++;
				int _X = X;
				X = (A * X + B) % C;
				if (_X == Y[i]) break;
				if (cnt > 10000) break;
			}
			if (cnt > 10000) break;
		}
		cout << (cnt <= 10000 ? cnt : -1) << endl;
	}
}

Measured memory_bytes: 1196
#include <stdio.h>
long long factorial(long long n){
	if(n==1) return 1;
	return n*factorial(n-1);
}
int main(void)
{
	long n;
	do{scanf("%d",&n);}while(1>n||20<n);
	printf("%lld\n",factorial(n));
	return 0;
}

Measured memory_bytes: 1756
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
vector <int> v;

int32_t main()
{
	usecppio
	int pt = 0;
	int n;
	cin >> n;
	v.resize(n);
	for (int i = 0; i<n; i++)
		cin >> v[i];
	for (int i = 0; i<n; i++)
	{
		if (v[i]==(pt+1)) pt++;
	}
	if (pt == 0) cout << -1 << '\n';
	else cout << (n-pt) << '\n';
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<map>
#define PRE std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
const int Mod = 1e9 + 7;
ll ls1[Max], ls2[Max],ls3[Max],sum[Max];

int main()
{
	PRE;
	ll n, m;
	cin >> n >> m;
	cout << ((100 * (n - m) + 1900 * m) * pow(2, m));
}

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

int main(){
	int n,count,max=0;
	string s;
	set <char>forward;
	set <char>back;

	cin >>n >>s;
	for(int i=0;i<n;i++){	
		count=0;
		for(int j=0;j<i;j++){
			forward.insert(s[j]);
		}
		for(int j=i;j<n;j++){
			back.insert(s[j]);
		}
		for(auto x:forward){
			for(auto y:back){
				if(x==y)count++;
			}
		}
		if(max<count)max=count;
		forward.clear();
		back.clear();
	}
	cout<<max<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

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

int main()
{
   long a, b;
   cin >> a >> b;
   cout  << lcm(a, b) << endl;
   return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>

using namespace std;

#define MAX 100000
#define INF 2140000000
#define MOD 1000000007

int main() {
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};

	int k;
	cin >> k;

	cout << a[k - 1] << endl;

	return 0;
}

Measured memory_bytes: 256
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        if (n == 1) { Console.WriteLine(0); goto exit; }
        long ans = (n + 1L) * (n - 2L) / 2L + 1L;
        Console.WriteLine(ans);
    exit:;
    }
}

Measured memory_bytes: 13140
#include<stdio.h>
int root(int n){
    for(int i=0;i<=n;i++)
        if(i*i==n)
            return 1;
    return 0;
}
int power(int a){if(a<0) a=-a;return a*a;}
int main(){
    int i,j,n,d,count=0,sum;
    scanf("%d%d",&n,&d);
    int x[n][d];
    for(i=0;i<n;i++)
        for(j=0;j<d;j++)
            scanf("%d",&x[i][j]);
    for(i=0;i<n-1;i++)
        for(j=i+1;j<n;j++){
            sum=0;
            for(int k=0;k<d;k++)
                sum+=power(x[i][k]-x[j][k]);
            if(root(sum))
                count++;
            }
    printf("%d\n",count);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

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

        int maxIndex = 0;
        int max = 100;
        int[] prices = new int[n];
        for (int i = 0; i < n; i++) {
            prices[i] = sc.nextInt();
            if (prices[i] >= max) {
                maxIndex = i;
                max = prices[i];
            }
        }
        prices[maxIndex] = prices[maxIndex] / 2;

        int sum = 0;
        for (int price: prices) {
            sum += price;
        }
        System.out.println(sum);
    }
}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define I(x, a) for(auto x : a)
#define F(i, l, r) for(auto i = l; i < r; ++i)
#define E(i, l, r) for(auto i = l; i <= r; ++i)
#define DF(i, l, r) for(auto i = l; i >= r; --i)
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define ret return
#define cont continue
#define brk break
#define ins insert
#define sz(a) ((int)(a).size())

typedef long long ll;
typedef unsigned long long ull;
typedef long double dbl;
typedef pair <int, int> pii;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const int mod = (int)1e9 + 7;
const dbl eps = (dbl)1e-8;
const int maxn = (int)1e5 + 5;
const dbl pi = acos(-1);

int winr(ll l, ll r) {
	return (r > l);
}

int n;
ll s, x[maxn], cnt[maxn];
ll ans;

int main() {
//	fin("t.in");
	sync;
	cin >> n >> s;
	F(i, 0, n) {
		cin >> x[i] >> cnt[i];
	}
	ans = 0;
	int l = 0, r = n - 1;
	while (1) {
		if (x[r] <= s) {
			ans += (s - x[l]);
			break;
		}
		if (x[l] >= s) {
			ans += (x[r] - s);
			break;
		}
		ans += (x[r] - x[l]);
		if (winr(cnt[l], cnt[r])) {
			cnt[r] += cnt[l];
			++l;
			while (x[l] < s && winr(cnt[l], cnt[r])) {
				cnt[r] += cnt[l];
				++l;
			}
		} else {
			cnt[l] += cnt[r];
			--r;
			while (x[r] > s && !winr(cnt[l], cnt[r])) {
				cnt[l] += cnt[r];
				--r;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		int x = fs.nextInt();
		int y = fs.nextInt();
		
		int ans = 0;
		
		if(x == 3) {
			ans += 100000;
		}else if(x == 2){
			ans += 200000;
		}else if(x == 1){
			ans += 300000;
		}
		
		if(y== 3) {
			ans += 100000;
		}else if(y == 2) {
			ans += 200000;
		}else if(y == 1) {
			ans += 300000;
		}
		
		if(x == 1 && y == 1) {
			ans += 400000;
		}
		
		System.out.println(ans);
		
	}	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 21204
import sys
s=input()
if(len(s)%2==1):
	print('No')
	sys.exit()
for i in range(len(s)):
	if i % 2 == 0:
		if s[i]!='h':
			print('No')
			sys.exit()
	else:
		if s[i]!='i':
			print('No')
			sys.exit()
print('Yes')


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <string.h>
#include <bitset>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;
    if (B % A == 0)
    {
        cout << (A + B) << endl;
    }
    else
    {
        cout << (B - A) << endl;
    }
    return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

using P = pair<int, PII>;

/* -----  2017/09/20  Problem: ACPC2017_day3_e  / Link:   ----- */
/* ------??????------



-----?????????????????§----- */
/* -----?§£??¬???-----



----?§£??¬???????????§---- */

LL N;
struct BIT2D {
	int _H, _W;
	VVI data;
	BIT2D(int h, int w) {
		_H = h; _W = w;
		data = VVI(_H + 1, VI(_W + 1, 0));
	}
	void add(int a, int b, int val) {
		for (int x = a; x <= _W; x += x&-x) {
			for (int y = b; y <= _H; y += y&-y) {
				data[x][y] += val;
			}
		}
	}
	int _sum(int a, int b) {
		int ret = 0;
		for (int x = a; x > 0; x -= x & -x) {
			for (int y = b; y > 0; y -= y & -y) {
				ret += data[x][y];
			}
		}
		return ret;
	}
	int sum(int lx, int ly, int rx, int ry) {
		return _sum(rx, ry) - _sum(lx - 1, ry) - _sum(rx, ly - 1) + _sum(lx - 1, ly - 1);
	}
};

LL ans = 0LL;
int H, W, T, Q;

int main() {

	scanf("%d%d%d%d", &H, &W, &T, &Q);
	BIT2D yet(max(W, H) + 1, max(W, H) + 1);// 1index
	BIT2D done(max(W, H) + 1, max(W, H) + 1);// 1index

//	bit.add(1, 1, 1);	bit.add(2, 2, 2);
//	cout << bit.sum(2, 2) << endl; (2,2)??????

	queue<P> que;
	FOR(i, 0, Q) {
		int t, c, h1, w1, h2, w2;
		scanf("%d%d%d%d", &t, &c, &h1, &w1);

		while (!que.empty()) {
			P p = que.front();
			if (p.first + T <= t) {
				que.pop();
				int Y = p.second.first, X = p.second.second;
				yet.add(Y, X, -1);
				done.add(Y, X, 1);
			}
			else break;

		}

		if (c != 2) {
			if (c == 0) {
				if (yet.sum(h1, w1, h1, w1) == 0 && done.sum(h1, w1, h1, w1) == 0) {
					yet.add(h1, w1, 1);
					que.push({ t,PII(h1,w1) });
				}
			}
			else {//c ==1
				if (done.sum(h1, w1, h1, w1) == 1) {
					done.add(h1, w1, -1);
				}
			}
		}
		else {
			scanf("%d%d", &h2, &w2);
			printf("%d %d\n", done.sum(h1, w1, h2, w2), yet.sum(h1, w1, h2, w2));
		}

	}



	return 0;
}

Measured memory_bytes: 35476
def enum_div_pairs(n):
    res = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            res.append((i, n // i))
    return res


def f(x, y):
    return max(map(lambda z: len(str(z)), [x, y]))


N = int(input())
divs = enum_div_pairs(N)
print(min(f(x, y) for x, y in divs))



Measured memory_bytes: 9448
import sys
input = sys.stdin.readline
H, W, N = map(int, input().split())
a = []
mod = 10 ** 9 + 7
for _ in range(N):
  x, y = map(int, input().split())
  a.append((x, y))
a.sort(key = lambda x: (x[0], x[1]))

class Factorial:
  def __init__(self, n, mod):
    self.f = [1]
    for i in range(1, n + 1):
      self.f.append(self.f[-1] * i % mod)
    self.i = [pow(self.f[-1], mod - 2, mod)]
    for i in range(1, n + 1)[: : -1]:
      self.i.append(self.i[-1] * i % mod)
    self.i.reverse()
  def factorial(self, i):
    return self.f[i]
  def ifactorial(self, i):
    return self.i[i]
  def combi(self, n, k):
    return self.f[n] * self.i[n - k] % mod * self.i[k] % mod

f = Factorial(H + W, mod)
dp = [[0] * 2 for _ in range(N)]
for i in range(N):
  x, y = a[i]
  dp[i][1] = f.combi(x + y - 2, x - 1) % mod
for i in range(N):
  x, y = a[i]
  for j in range(N):
    if i == j: continue
    u, v = a[j]
    if u >= x and (v >= y):
      t = f.combi(u + v - (x + y), u - x)
      dp[j][0] += t * dp[i][1]
      dp[j][0] %= mod
      dp[j][1] += t * dp[i][0]
      dp[j][1] %= mod
res = f.combi(H + W - 2, H - 1)
for i in range(N):
  x, y = a[i]
  res += dp[i][0] * f.combi(H + W - x - y, H - x)
  res %= mod
  res -= dp[i][1] * f.combi(H + W - x - y, H - x)
  res %= mod
print(res)

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

#define fi first
#define se second
#define mp make_pair
typedef pair<int, int> ii;

const int mod = 1e9+7, len = 2e5+5;
int per[len], rev[len], dp[len];
ii arr[len];

int add(int a, int b){
    return (a+b)%mod;
}

int mul(int a, int b){
    return (a*1LL*b)%mod;
}

int sub(int a, int b){
    return (mod+a-b)%mod;
}

int po(int a, int b){
    if (b == 0) return 1;
    if (b%2 == 0) return po(mul(a, a), b/2);
    return mul(a, po(mul(a, a), b/2));
}

int cho(int n, int k){
    return mul(per[n], mul(rev[n-k], rev[k]));
}

int main(){
    int h, w, n;
    scanf("%d %d %d", &h, &w, &n);
    for (int i = 0; i < n; i++)
        scanf("%d %d", &arr[i].fi, &arr[i].se);
    arr[n] = mp(h, w);

    sort(arr, arr+n);

    per[0] = rev[0] = 1;
    for (int i = 1; i <= h+w; i++){
        per[i] = mul(per[i-1], i);
        rev[i] = po(per[i], mod-2);
    }

    for (int i = 0; i <= n; i++){
        dp[i] = cho(arr[i].fi+arr[i].se-2, arr[i].fi-1);
        for (int j = 0; j < i; j++)
            if (arr[j].fi <= arr[i].fi && arr[j].se <= arr[i].se)
                dp[i] = sub(dp[i], mul(dp[j], cho(arr[i].fi+arr[i].se-arr[j].fi-arr[j].se, arr[i].fi-arr[j].fi)));
    }

    //for (int i = 0; i <= n; i++)
      //  printf("i = %d, arr[i] = (%d, %d), dp[i] = %d\n", i, arr[i].fi, arr[i].se, dp[i]);

    printf("%d\n", dp[n]);
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A=0, B=0;
  cin >> N;
  vector<int> cards(N);
  
  for(int i=0; i<N;i++){
    cin >> cards.at(i);
  }
  
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  
  for(int i=0;i<N;i++){
    if(i%2==0){
      A+=cards.at(i);
    }
    else{
      B+=cards.at(i);
    }
  }
  cout << A - B << endl;
}

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

ll a,b,k;
string s,t;

int main() {
  cin >> a >> b >> k;
  if(k<=a) a-=k;
  else if(k<=a+b){
    b-=k-a,a=0;
  } else {
    a=0,b=0;
  }
  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
def f(n, r, mod=10 ** 9 + 7):
	n += r
	assert n >= r >= 0

	def ex_euclid(x, y):
		a, b = 1, 0
		while y != 0:
			a, b = b, (a - x // y * b)
			x, y = y, x % y
		return a

	p = q = 1
	for i in range(n - r + 1, n + 1):
		p *= i
		p %= mod
	for i in range(2, r + 1):
		q *= i
		q %= mod
	p *= ex_euclid(q, mod)
	p %= mod
	return p

a,b,c,d=map(int,input().split())
mod=10**9+7
print((f(c+1,d+1)+mod-f(a,d+1)+mod-f(c+1,b)+f(a,b))%mod)

Measured memory_bytes: 3064
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
# from copy import deepcopy, copy

import queue
from collections import deque


# def comb(n, r, mod):
#     ans = 1
#     for i in range(max(r, n - r) + 1, n + 1):
#         ans *= i
#         ans %= mod
#     for i in range(1, min(r, n - r) + 1):
#         ans *= pow(i, mod - 2, mod)
#         ans %= mod
#     return ans

def comb(n, r, mod, comb_list):
    ans = comb_list[n]
    ans *= pow(comb_list[r], mod - 2, mod)
    ans %= mod
    ans *= pow(comb_list[n - r], mod - 2, mod)
    ans %= mod
    return ans


def main():
    data = list(map(int, list(input())))
    length = len(data)
    mod = 10 ** 9 + 7

    dp1 = [0 for i in range(length)]
    dp2 = [0 for i in range(length)]

    dp1[0] = 1
    dp2[0] = 2

    for i in range(1, length):
        if data[i]:
            dp1[i] += 3 * dp1[i - 1]
            dp1[i] += dp2[i - 1]
            dp2[i] = 2 * dp2[i - 1]
        else:
            dp1[i] += 3 * dp1[i - 1]
            dp2[i] = dp2[i - 1]
        dp1[i] %= mod
        dp2[i] %= mod

    ans = (dp1[-1] + dp2[-1]) % mod
    print(ans)





if __name__ == '__main__':
    main()


Measured memory_bytes: 52980
//{{{
#include<algorithm>
#include<cmath>
#include<deque>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(printde) FUNC(printdbe) FUNC(printdwe) FUNC(printdu);
#endif
template <template <class T, class = std::allocator<T>> class V, class E>
istream& operator >> (istream& in, V<E>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int n; cin >> n;
    vector<int> as(n); cin >> as;
    vector<int> bs(n); cin >> bs;
    vector<int> cs(n), cs0(n);
    int ans = M;
    for(int i = 0; i < (1 << n); i++){
        if(__builtin_popcount(i) & 1){
            continue;
        }
        for(int j = 0; j < n; j++){
            cs0[j] = (i >> j & 1) ? - bs[j] : as[j];
            cs[j] = (i >> j & 1) ? bs[j] : as[j];
        }
        sort(cs.begin(), cs.end());
        printde(i);
        printde(cs0);
        printde(cs);
        bool ok = true;
        int cnt = 0;
        for(int j = 0; j < n - 1 && ok; j++){
            // int jj = (i >> j & 1) ? j - 1 : j;
            ok = false;
            for(int k = j; k < n; k++){
                if(cs[j] == cs0[k] * (((k - j) & 1) ? -1 : 1)){
                    for(int kk = k - 1; kk >= j; kk--){
                        swap(cs0[kk], cs0[kk + 1]);
                        cs0[kk] *= -1;
                        cs0[kk + 1] *= -1;
                        cnt++;
                    }
                    printde(cs0, j, k);
                    ok = true;
                    break;
                }
            }
            printde(j, ok);
        }
        if(ok){
            ans = min(ans, cnt);
            printde(i, ans);
        }
    }
    cout << (ans == M ? -1 : ans) << '\n';
}


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

void bfs(int H, int W, vector<vector<char>> maze, vector<vector<int>> &distance) {
    
    int INF = 1000000;
    vector<int> dx = {1, 0, -1, 0};
    vector<int> dy = {0, -1, 0, 1};
    queue <pair<int, int>> que; //これからみるマスをしまう
    
    for(int i = 0; i < H; i++) {
        for(int j= 0; j < W; j++) {
            if(maze.at(i).at(j)=='#') {
                que.push(pair<int, int> (i, j));
                distance.at(i).at(j) = 0;
            }
        }
    }
    
    vector<vector<bool>> reached(H, vector<bool>(W));
    while (que.size() != 0) {
        pair<int, int> now = que.front();
        que.pop();
        
        for(int i = 0; i < 4; i++) {
            
            int ny = now.first + dy.at(i);
            int nx = now.second + dx.at(i);
            
            if(0<=ny && ny<H && 0<=nx && nx<W && !(reached.at(ny).at(nx))) {
                reached.at(ny).at(nx) = true;
                if(distance.at(ny).at(nx) > distance.at(now.first).at(now.second) + 1) {
                    que.push(pair<int, int> (ny, nx));
                    distance.at(ny).at(nx) = distance.at(now.first).at(now.second) + 1;
                }
            }
            
        }
    }

}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> maze(H, vector<char>(W));
    for(int i = 0; i < H; i++) {
        for(int j= 0; j < W; j++) {
            cin >> maze.at(i).at(j);
        }
    }
    vector<vector<int>> distance(H, vector<int>(W, 1000000));
    
    bfs(H, W, maze, distance);
    
    int ans = 0;
    for(int i = 0; i < H; i++) {
        for(int j= 0; j < W; j++) {
            ans = max(ans, distance.at(i).at(j));
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 14608
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    const char Wh = '.';
    const char Bl = '#';
    const char Sp = ' ';

    static object process(TextReader input) {
        var spl = input.ReadLine().Split(' ');
        var h = int.Parse(spl[0]);
        var w = int.Parse(spl[1]);

        var aa = new char[h][];
        for(int i =0; i<h; i++) {
            var s = input.ReadLine();
            aa[i] = s.ToCharArray();
        }

        var dicH = new HashSet<int>();
        var dicW = new HashSet<int>();

        for (int i=0; i<h; i++) {
            for(int j=0; j<w; j++) {
                if(aa[i][j] == Bl) {
                    if (!dicH.Contains(i)) dicH.Add(i);
                    if (!dicW.Contains(j)) dicW.Add(j);
                }
            }
        }

        var sb = new StringBuilder();
        for (int i = 0; i < h; i++) {
            bool exist = false;
            for (int j = 0; j < w; j++) {
                if(dicH.Contains(i) && dicW.Contains(j)) {
                    sb.Append(aa[i][j]);
                    exist = true;
                }
            }
            if (exist) sb.AppendLine();
        }

        return sb;
    }
}


Measured memory_bytes: 11360
#include <iostream>
#include <algorithm>
#include <deque>
#include <string>

using namespace std;

int fr[10010];

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	long long res = 0;
	int n,p,v;
	cin>>n>>p;
	string s;
	cin>>s;
	if(p==2||p==5){
		int ac = 0;
		for(int i=n-1;i>=0;i--){
			v = s[i]-'0';
			if(v%p==0)ac++;
			res+=ac;
		}
	}
	else{
		int ba = 1;
		int ac = 0;
		fr[0]=1;
		for(int i=n-1;i>=0;i--){
			v = s[i]-'0';
			ac = (ac + v*ba)%p;
			res+=fr[ac];
			fr[ac]++;
			ba = (ba*10)%p;
		}
	}
	
	cout<<res<<endl;
	
	return 0;
}

Measured memory_bytes: 832
#include<stdio.h>
#include<math.h>

#define N 1000000
#define INFTY 2000000000

int A[N],c=0;

void Merge(int,int,int);
void MergeSort(int,int);

int main(){
  int i,m;

  scanf("%d",&m);

  for(i=0;i<m;i++)
  scanf("%d",&A[i]);

  MergeSort(0,m);

  for(i=0;i<m;i++){
    printf("%d",A[i]);
    if(i!=m-1)printf(" ");
  }
  printf("\n%d\n",c);
  return 0;
}
void Merge(int left,int mid,int right)
{
  int n1,n2,i,j,k,L[N],R[N];

  n1 = mid - left;
  n2 = right - mid;
  for(i=0;i<=n1-1;i++) 
    L[i] = A[left + i];
  
  for(i=0;i<=n2-1;i++)
    R[i] = A[mid + i];
      
  L[n1] = INFTY;
  R[n2] = INFTY;
  i = 0;
  j = 0;
      
  for (k=left;k<=right-1;k++)
    if (L[i] <= R[j]){
      A[k] = L[i];
      i = i + 1;
      c++;
    }
    else{
      A[k] = R[j];
      j = j + 1;
      c++;
    }
}
void  MergeSort(int left,int right){
  int mid;
  if (left+1 < right){
    mid = (left + right)/2;
    MergeSort(left, mid);
    MergeSort(mid, right);
    Merge(left, mid, right);
  }
}

Measured memory_bytes: 7632