akhauriyash/Code-Regression huggingface dataset:
use std::io::{Read, StdinLock};
use std::str::{from_utf8, FromStr};
use std::vec::Vec;

const EPS: f64 = 1e-6;

struct StdinReader<'a> {
    reader: StdinLock<'a>,
}

impl<'a> StdinReader<'a> {
    pub fn new(reader: StdinLock<'a>) -> StdinReader {
        StdinReader { reader: reader }
    }

    pub fn read<T: FromStr>(&mut self) -> T {
        fn is_whitespace(ch: u8) -> bool {
            ch == 0x20 || ch == 0x0a || ch == 0x0d
        }

        let token: Vec<u8> = self.reader
            .by_ref()
            .bytes()
            .map(|ch| ch.expect("failed to read a byte"))
            .skip_while(|ch| is_whitespace(*ch))
            .take_while(|ch| !is_whitespace(*ch))
            .collect();
        let token_str = from_utf8(&token)
            .unwrap_or_else(|_| panic!(format!("invalid utf8 sequence: {:?}", token)));
        token_str
            .parse()
            .unwrap_or_else(|_| panic!(format!("failed to parse input: {}", token_str)))
    }
}

fn distance(p1: (f64, f64), p2: (f64, f64)) -> f64 {
    let dx = p1.0 - p2.0;
    let dy = p1.1 - p2.1;
    (dx * dx + dy * dy).sqrt()
}

fn dfs(visited: u32, p: (f64, f64), t: f64, crystals: &[(f64, f64)]) -> bool {
    let n = crystals.len();
    if visited == (1 << n) - 1 {
        return true;
    }

    // すべての頂点に到達可能かどうかをチェック
    for v in 0..n {
        if visited & (1 << v) != 0 { continue; }
        let q = crystals[v];
        let d = distance(p, q);
        if t + d >= distance(q, (0.0, 0.0)) - EPS {
            return false;
        }
    }

    for v in 0..n {
        if visited & (1 << v) != 0 { continue; }
        let q = crystals[v];
        let d = distance(p, q);
        if dfs(visited ^ (1 << v), q, t + d, crystals) {
            return true;
        }
    }
    false
}

fn main() {
    let stdin = std::io::stdin();
    let mut reader = StdinReader::new(stdin.lock());

    loop {
        let n: usize = reader.read();
        let hx: f64 = reader.read();
        let hy: f64 = reader.read();
        let dx: f64 = reader.read();
        let dy: f64 = reader.read();
        let start = (hx - dx, hy - dy);
        if n == 0 { break; }

        let mut crystals: Vec<(f64, f64)> = Vec::new();
        for _ in 0..n {
            let cx = reader.read::<f64>() - dx;
            let cy = reader.read::<f64>() - dy;
            crystals.push((cx, cy));
        }

        let ok = dfs(0, start, 0.0, &crystals);

        println!("{}", if ok { "YES" } else { "NO" });
    }
}



Measured memory_bytes: 5048
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;
const int inf = 1e17+21;

int sod(int x){
    int sum = 0;
    while(x > 0){
        sum += x%10;
        x /= 10;
    }

    return sum;
}

int32_t main(){
    FAST;

    string s;   cin >> s;
    for(int x=0;x<s.size();x+=2)
        cout << s[x];

    return 0;
}


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

int main() {
    int n, a[100000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    int q, key, sum = 0;
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> key;
        if (*lower_bound(a, a + n, key) == key) {
            sum++;
        }
    }
    cout << sum << endl;
}



Measured memory_bytes: 3472
N = int(input())

def keta(N):
    ten = 1
    for i in range(1, 8):
        if N/ten < 1:
            break
        ten = ten*10
    return i-1
        
if keta(N)==1:
    ans = N
elif keta(N)==2:
    ans = 9
elif keta(N)==3:
    ans = 9 + N-99
elif keta(N)==4:
    ans = 909
elif keta(N)==5:
    ans = 909 + N-9999
elif keta(N)==6:
    ans = 90909

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ll inf = 1LL << 60;
const ld pi = (acos(-1));
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n; cin >> n;
  string ans="No";
  rep(i,1,10)rep(j,1,10){
    if(n==i*j){
      ans = "Yes";
      break;
    } 
  }
  cout << ans << endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  int n;
  cin >> n;
  vector<ll> alp(5);
  rep (i, n) {
    string s;
    cin >> s;
    if (s[0] == 'M') alp[0]++;
    if (s[0] == 'A') alp[1]++;
    if (s[0] == 'R') alp[2]++;
    if (s[0] == 'C') alp[3]++;
    if (s[0] == 'H') alp[4]++;
  }

  ll ans = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = i + 1; j < 4; j++) {
      for (int k = j + 1; k < 5; k++) {
        ans += alp[i] * alp[j] * alp[k];
      }
    }
  }

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


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

bool solve(int N, const std::vector<std::string>& words)
{
    auto c = words[0].back();

    std::set<std::string> S;
    S.insert(words[0]);

    for (int i = 1; i < N; ++i)
    {
        if (S.count(words[i]) or words[i].front() != c)
            return false;

        c = words[i].back();
        S.insert(words[i]);
    }

    return true;
}

int main()
{
    std::ios::sync_with_stdio(false);

    int N;
    std::cin >> N;

    std::vector<std::string> words(N);

    for (int i = 0; i < N; ++i)
        std::cin >> words[i];

    auto ans = solve(N, words);

    std::cout << (ans ? "Yes\n" : "No\n");

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
//long long ccw(const Point& A, const Point& B, const Point& C) {
//	return 1LL * (B.x - A.x)*(C.y - A.y) - 1LL * (B.y - A.y)*(C.x - A.x);
//}

int main() {
	// 최대유량, 앳코더, (종만북(?) 생각) - 기하 잘하고 싶다!
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll x; cin >> x;
	ll tmp = x;
	ll ans = 0;
	while (tmp > 0) {
		ans += tmp % 10;
		tmp /= 10;
	}
	if (x % ans == 0) {
		cout << "Yes" << '\n';
	}
	else {
		cout << "No" << '\n';
	}




}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i, x, y) for(int i = x, _b = y; i <= _b; i ++)
#define ff(i, x, y) for(int i = x, _b = y; i <  _b; i ++)
#define fd(i, x, y) for(int i = x, _b = y; i >= _b; i --)
#define ll long long
#define pp printf
#define hh pp("\n")
using namespace std;

const int N = 3e5 + 5;

int w, h, n;

struct P {
	int x, y;
} a[N];

int ans;

int d[N], d0;

map<int, int> rd;

void ls() {
	d0 = 0; d[++ d0] = 0; d[++ d0] = w;
	fo(i, 1, n) d[++ d0] = a[i].x;
	sort(d + 1, d + d0 + 1);
	d0 = unique(d + 1, d + d0 + 1) - (d + 1);
	rd.clear(); fo(i, 1, d0) rd[d[i]] = i;
}

P b[N], c[N]; int b0, c0;

int op;

int cmp1(P a, P b) {
	if(a.x == b.x) {
		if(a.y == b.y) return 0;
		return (a.y < b.y) ^ op;
	}
	return a.x < b.x;
}

void gg(P *a, int &a0) {
	sort(a + 1, a + a0 + 1, cmp1);
	int A = a0; a0 = 0;
	fo(i, 1, A) if(i == 1 || a[i].x != a[a0].x)
		a[++ a0] = a[i];
}

int t[N * 4], lz[N * 4], pl, pr, px;
#define i0 i + i
#define i1 i + i + 1
void jia(int i, int x) { t[i] += x, lz[i] += x;}
void down(int i) { if(lz[i]) jia(i0, lz[i]), jia(i1, lz[i]), lz[i] = 0; }
void add(int i, int x, int y) {
	if(y < pl || x > pr) return;
	if(x >= pl && y <= pr) { jia(i, px); return;}
	int m = x + y >> 1; down(i);
	add(i0, x, m); add(i1, m + 1, y);
	t[i] = max(t[i0], t[i1]);
}
void pla(int x, int y, int z) {
	pl = x, pr = y, px = z;
	add(1, 1, d0);
}

int z1[N], z2[N];

void ad1(int f) {
	P u = b[z1[z1[0] - 1]], v = b[z1[z1[0]]];
	pla(rd[u.x], rd[v.x] - 1, f * (h - v.y));
}

void ad2(int f) {
	P u = c[z2[z2[0] - 1]], v = c[z2[z2[0]]];
	pla(rd[u.x], rd[v.x] - 1, f * v.y);
}

void work() {
	ls();
	b0 = c0 = 0;
	fo(i, 1, n)	if(a[i].x) {
		if(a[i].y >= h / 2) b[++ b0] = a[i];
		if(a[i].y <= h / 2) c[++ c0] = a[i];
	}
	op = 0; gg(b, b0);
	op = 1; gg(c, c0);
	
	fo(i, 1, d0 * 4) lz[i] = 0, t[i] = 0;
	
	b[0] = c[0] = (P) {0, h / 2};
	z1[0] = z2[0] = 1;
	z1[1] = z2[1] = 0;
	
	int l1 = 1, l2 = 1;
	fo(i, 1, d0) {
		while(l1 <= b0 && b[l1].x < d[i]) {
			while(b[l1].y < b[z1[z1[0]]].y)
				ad1(1), z1[0] --;
			z1[++ z1[0]] = l1; ad1(-1);
			l1 ++;
		}
		while(l2 <= c0 && c[l2].x < d[i]) {
			while(c[l2].y > c[z2[z2[0]]].y)
				ad2(1), z2[0] --;
			z2[++ z2[0]] = l2; ad2(-1);
			l2 ++;
		}
		ans = max(ans, t[1] + d[i]);
		
		pl = pr = i; px = h - d[i];
		add(1, 1, d0);
	}
	
}

int main() {
	scanf("%d %d %d", &w, &h, &n);
	fo(i, 1, n) scanf("%d %d", &a[i].x, &a[i].y), a[i].x *= 2, a[i].y *= 2;
	w *= 2, h *= 2;
	ans = max(w, h);
	work();
	swap(w, h); fo(i, 1, n) swap(a[i].x, a[i].y);
	work();
	pp("%d\n", ans);
}

Measured memory_bytes: 32768
import java.util.Scanner;

public class Main 
{
	static class Tile
	{
		String arrow;
		String pass;
		public Tile()
		{
			pass = "";
		}
	}
	
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		
		
		for(; ;)
		{
			int h = scanner.nextInt();
			int w = scanner.nextInt();
			if(w==0 && h==0)
			{
				break;
			}
			
			Tile[][] tile = new Tile[h][w];
			for(int i=0; i<h; i++)
			{
				String input = scanner.next();
				for(int j=0; j<w; j++)
				{
					tile[i][j] = new Tile();
					tile[i][j].arrow = input.substring(j, j+1);
				}
			}
			
			int x = 0;
			int y = 0;
			for(; ;)
			{
				String output = "";
				if(tile[y][x].pass.equals(""))
				{
					tile[y][x].pass = tile[y][x].arrow;
					switch(tile[y][x].arrow)
					{
						case ">":
							x ++;
							break;
						case "<":
							x --;
							break;
						case "^":
							y --;
							break;
						case "v":
							y ++;
							break;
						case ".":
							output = x+" "+y;
							break;
					}
				}
				else
				{
					output = "LOOP";
				}
				
				if(!output.equals(""))
				{
					System.out.println(output);
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 30136
#include <iostream>
#include <array>

int main(void)
{
    int x,y;
    std::cin >> x;
    std::cin >> y;    
    if (x == y) {
        std::cout << "a == b" << std::endl;
    } else if (x < y) {
        std::cout << "a < b" << std::endl;
    } else if (x > y) {
        std::cout << "a > b" << std::endl;    
    }
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> input(n,0);
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> input.at(i);
  }
  
  int max = 0;
  for (int i = 0; i < n; i++) {
    if(i < m){
      sum += input[i];
    }else{
      sum = sum - input[i-m] + input[i];
    }
    if(sum > max) max = sum;
  }
  
  cout << (max + m)/2;
  
  if((max + m)%2 == 0)
    cout << ".0" << endl;
  else
    cout << ".5" << endl;
  
  return 0;
}



Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 30;
const int MOD = 1e9 + 7;

int main() {
  int n;
  scanf("%d", &n);
  int64 ret = 1, v = 1;
  for (int i = 0; i < n; ++i) ret *= 3;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    if (x % 2) {
      v *= 1;
    } else {
      v *= 2;
    }
  }
  printf("%lld\n", ret - v);
  return 0;
}


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

#define int long long

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

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


int N,M;
int A[222222],B[222222];
bool flag1[222222],flag2[222222];

vint G[1111];

int r[1111];
bool used[1111];

void solve(int s){
    memset(r,-1,sizeof(r));
    memset(used,0,sizeof(used));

    for(auto v:G[s]){
        if(r[v]!=-1){
            used[v]=true;
            continue;
        }
        r[v]=v;
        queue<int>que;
        que.push(v);
        while(que.size()){
            int u=que.front();
            que.pop();
            for(auto w:G[u]){
                if(w==s)continue;
                if(r[w]!=-1){
                    if(r[w]!=v)used[w]=true;
                    continue;
                }
                r[w]=v;
                que.push(w);
            }
        }
    }

    queue<int>que;
    rep(i,N)if(used[i])que.push(i);

    while(que.size()){
        int v=que.front();
        que.pop();
        for(auto u:G[v]){
            if(u==s)continue;
            if(used[u])continue;
            used[u]=true;
            que.push(u);
        }
    }

    rep(i,M){
        if(A[i]==s){
            flag1[i]|=used[B[i]];
        }
        if(B[i]==s){
            flag2[i]|=r[A[i]]!=-1;
        }
    }
}

signed main(){
    cin>>N>>M;
    rep(i,M){
        cin>>A[i]>>B[i];A[i]--;B[i]--;
        G[A[i]].pb(B[i]);
    }

    rep(i,N)solve(i);
    rep(i,M){
        if(flag1[i]==flag2[i])puts("same");
        else puts("diff");
    }
    return 0;
}


Measured memory_bytes: 8064
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#define fo(i,n) for(long long i=0;i<n;i++)
#define ll long long int
#define inf 999999999999999999
#define pb push_back
#define MOD 1000000007
#define tr(c,it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define fio ios_base::sync_with_stdio(false);cin.tie(0);
using namespace std;
//cerr<< '\n' << "Time elapsed :" << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n" ;
//freopen("explicit.in", "r", stdin);
//freopen("explicit.out", "w", stdout);
 
void SieveOfEratosthenes() 
{ 
    bool prime[10000001];
    memset(prime, true, sizeof(prime)); 
  
    for (ll p=2; p*p<=10000000; p++) 
    { 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (ll i=p*p; i<=10000000; i += p) {
                prime[i] = false; 
            }
        } 
    }  
} 
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a);
        a = (a * a);
        b >>= 1;
    }
    return res;
}
ll gcd(ll a,ll b)
{
	if(b%a==0)
	   return a;
	return gcd(b%a,a);
}
ll nCrModpDP(ll n, ll r, ll p) 
{ 
    ll C[r+1]; 
    memset(C, 0, sizeof(C));   
    C[0] = 1;
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 
ll nCrModp(ll n, ll r, ll p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
   ll ni = n%p, ri = r%p; 
  
   return (nCrModp(n/p, r/p, p) * 
           nCrModpDP(ni, ri, p)) % p; 
} 
int32_t main() 
{
    fio
	ll j,i,n,t,l,r,c,h,k,maxi,d,x;
	cin>>n;
	string s;
	map<string,ll> m;
	for(j=0;j<n;j++)
	{
		cin>>s;
		m[s]++;
	}
	cout<<"AC x "<<m["AC"]<<endl;
	cout<<"WA x "<<m["WA"]<<endl;
	cout<<"TLE x "<<m["TLE"]<<endl;
	cout<<"RE x "<<m["RE"]<<endl;

}



	

		

Measured memory_bytes: 3660
import fractions
from functools import reduce

n, x = [int(x) for x in input().split()]
xlist = [int(x) for x in input().split()]
xlist.append(x)
xlist.sort()
distlist = []
for i in range(len(xlist) - 1):
    distlist.append(xlist[i+1] - xlist[i])

def gcd(numbers):
    return reduce(fractions.gcd, numbers)

print(gcd(distlist))


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

int main() {
  int N;
  string s;
  cin >> N >> s;
  int pat = 0;
  for (char i = '0'; i <= '9'; i++) {
    for (char j = '0'; j <= '9'; j++) {
      for (char k = '0'; k <= '9'; k++) {
        int pos = 0;
        for (int h = 0; h < N; h++) {
          if (pos == 0 && s[h] == i) pos += 1;
          else if (pos == 1 && s[h] == j) pos += 1;
          else if (pos == 2 && s[h] == k) {
            pat += 1;
            break;
          }
        }
      }
    }
  }
  cout << pat << endl;
}

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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// mod
const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

// floating
typedef double Real;
const Real EPS = 1e-11;
#define EQ0(x) (abs(x)<EPS)
#define EQ(a,b) (abs(a-b)<EPS)
typedef complex<Real> P;

int main(){
  int n;
  cin>>n;
  int x = 1;
  while(2*x<=n)x*=2;
  cout<<x<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n, c[666][8], u[4], z;
ll F(ll a, ll b, ll c, ll d) {
	return a << 30 | b << 20 | c << 10 | d;
}
map<ll, ll> g;
void A(ll x, ll v) {
	for (int i = 0; i < 4; i++) {
		g[x] += v;
		x = (x >> 10) | (x & 1023) << 30;
	}
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 4; j++) {
			cin >> c[i][j];
			c[i][j + 4] = c[i][j];
		}
		A(F(c[i][0], c[i][1], c[i][2], c[i][3]), 1);
	}
	for (int i = 0; i < n; i++) {
		A(F(c[i][0], c[i][1], c[i][2], c[i][3]), -1);
		for (int j = i + 1; j < n; j++) {
			A(F(c[j][0], c[j][1], c[j][2], c[j][3]), -1);
			for (int k = 0; k < 4; k++) {
				ll r = 1;
				u[0] = F(c[j][k + 1], c[j][k + 0], c[i][1], c[i][0]);
				u[1] = F(c[j][k + 0], c[j][k + 3], c[i][2], c[i][1]);
				u[2] = F(c[j][k + 3], c[j][k + 2], c[i][3], c[i][2]);
				u[3] = F(c[j][k + 2], c[j][k + 1], c[i][4], c[i][3]);
				if (g[u[0]] && g[u[1]] && g[u[2]] && g[u[3]]) {
					r *= g[u[0]];
					A(u[0], -1);
					r *= g[u[1]];
					A(u[1], -1);
					r *= g[u[2]];
					A(u[2], -1);
					r *= g[u[3]];
					A(u[2], 1);
					A(u[1], 1);
					A(u[0], 1);
					z += r;
				}
			}
			A(F(c[j][0], c[j][1], c[j][2], c[j][3]), 1);
		}
	}
	cout << z << endl;
	return 0;
}

Measured memory_bytes: 20352
#include<iostream>
#include<vector>
#include<string>
#include<map>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= (int)end; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
template<typename T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return 0;}
template<typename T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return 0;}

struct pos {
    int h, w;
    pos():h(-1), w(-1) {}
    pos(int h, int w):h(h), w(w) {}
    bool operator<(const pos& p) const {
        return h < p.h;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<int>> A(H, vector<int>(W));
    rep(i, 0, H) rep(j, 0, W) {
        cin >> A[i][j];
    }
    int Q;
    cin >> Q;
    vector<int> L(Q), R(Q);
    rep(i, 0, Q) {
        cin >> L[i] >> R[i];
    }
    map<int, pos> pos_map;
    rep(i, 0, H) rep(j, 0, W) {
        pos_map[A[i][j]] = pos(i, j);
    }
    vector<ll> cumsum(H * W + 1, 0);
    rep(i, 1, D + 1) {
        for (int j = i + D; j <= H * W; j += D) {
            int h1 = pos_map[j - D].h;
            int w1 = pos_map[j - D].w;
            int h2 = pos_map[j].h;
            int w2 = pos_map[j].w;
            cumsum[j] = abs(h1 - h2) + abs(w1 - w2) + cumsum[j - D];
        }
    }
    rep(i, 0, Q) {
        cout << cumsum[R[i]] - cumsum[L[i]] << endl;
    }
    return 0;
}

Measured memory_bytes: 8576
#include <iostream>
#include <limits.h>
#include <queue>
#include <algorithm>
#include <string>
//typedef pair<int,int> P;

using namespace std;

const int INF=INT_MAX/3;
const int V_MAX=10000,E_MAX=10000;

int H,W;
const int MAX=200;

char maps[MAX][MAX];

void solve(int i,int j){

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

  char c=maps[i][j];
  maps[i][j]='.';
  
  for(int k=0;k<4;k++){
    int ni=i+dx[k];
    int nj=j+dy[k];
    if((0<=ni && ni<H) && (0<=nj && nj<W))
      if(maps[ni][nj]!='.' && c==maps[ni][nj]){
	//cout<<"pohe"<<endl;
	solve(ni,nj);
      }
  }
  
  

}



int main(){

  int res=0;
  
  while(1){
    res=0;
    cin>>H>>W;
    if(H==0 && W==0) break;

    for(int i=0;i<H;i++){
      cin>>maps[i];
    }
    //cout<<"hoge\n";

    for(int i=0;i<H;i++)
      for(int j=0;j<W;j++){
	if(maps[i][j]!='.'){
	  solve(i,j);
	  res++;
	  //cout<<"piyo"<<endl;
	}
	/*
	for(int i=0;i<H;i++){
	  for(int j=0;j<W;j++){
	    cout<<maps[i][j]<<" ";
	  }
	  cout<<endl;
	}
	cout<<endl;
	*/
      }
    cout<<res<<endl;

    //cout<<solve()<<endl;
  }

  return 0;
}

Measured memory_bytes: 4020
import sys
input = sys.stdin.readline
INF = float('inf')

def dijkstra_al(s, n, ALcost):
    '''
    n: 頂点の数、s: 始点
    AL_cost[head] = [(tail, cost), ..., (tail, cost)]
    cost存在しないときはinf
    '''
    import heapq

    fixed = [False] * n # 重み確定したかどうか
    nfixed = 0 # 確定した数
    vertex_cost = [INF] * n  # 始点sから各頂点への重み

    # 1. 始点に0を書き込む
    vertex_cost[s] = 0
    H = []  # (cost, vertex)のheap
    heapq.heappush(H, (0, s))

    while(H): # Hが空になるまで
        # 2. 未確定の地点の中からもっとも小さい値を持つ地点を1つ選び、その値を確定させる
        u_cost, u = heapq.heappop(H)
        if fixed[u]: continue  # 取り出した頂点がすでに決まっている（古い情報）
        fixed[u] = True
        nfixed += 1

        # 3. 2で確定した地点から直接繋がっていて、かつ未確定な地点に対し、
        #    重みを計算し、書き込まれている値より小さければ更新する
        for v, cost in ALcost[u]:
            if fixed[v]: continue
            newcost = u_cost + cost
            if newcost < vertex_cost[v]:
                vertex_cost[v] = newcost
                heapq.heappush(H, (newcost, v))

        # 4. 全ての地点が確定していれば終了。そうでなければ2に戻る
        if nfixed == n: break

    return vertex_cost


def rc_to_v(y, x):
    return y * W + x

H, W = [int(x) for x in input().split()]
sy, sx = [int(x) - 1 for x in input().split()]
gy, gx = [int(x) - 1 for x in input().split()]
S = [list(input().strip()) for _ in range(H)]

AL = [[] for _ in range(H * W)]

for y in range(H):
    for x in range(W):
        if S[y][x] == '#':  continue

        for dy in range(-2, 3):
            for dx in range(-2, 3):
                ny = y + dy
                nx = x + dx
                if ny < 0 or H <= ny or nx < 0 or W <= nx:
                    continue
                if S[ny][nx] == '#':  # 行けない
                    continue
                if (dy, dx) in [(0, -1), (0, 1), (1, 0), (-1, 0)]:
                    AL[rc_to_v(y, x)].append((rc_to_v(ny, nx), 0))
                else:
                    AL[rc_to_v(y, x)].append((rc_to_v(ny, nx), 1))


cost = dijkstra_al(rc_to_v(sy, sx), H * W, AL)

ans = cost[rc_to_v(gy, gx)]
print(-1 if ans == INF else int(ans))

Measured memory_bytes: 428904
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace What_day_is_today
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string input = Console.ReadLine();
                
                string[] input1 = input.Split(' ');
                int mm = int.Parse(input1[0]);
                if (mm == 0) break;
                int dd = int.Parse(input1[1]);
                var d2004 = new DateTime(2004, mm, dd).DayOfWeek;
                Console.WriteLine(d2004);
            }
        }
    }
}



Measured memory_bytes: 15940
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9
#define PI 3.14159265359
#define MOD 1000000007
#define ALL(v) v.begin(),v.end()
#define ALLR(v) v.rbegin(),v.rend()
typedef long long ll;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//isPrime
//modpow modinv
//getDigit
int main() {
  cout << fixed << setprecision(10);
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a,c) << endl;
}


Measured memory_bytes: 256
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define divup(a,b) ( ( (a) + ( (b) - 1u) ) / (b) ) // a/b の余り切り上げ
// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;
ll mod = 1000000007;

signed main(){
    ll m1,d1,m2,d2;
    cin>>m1>>d1>>m2>>d2;
    if(m1!=m2) cout<<1<<endl;
    else cout<<0<<endl;
}


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

int N, L;
int Left[101], Right[101];

bool Check()
{
  for(int i = 0; i <= L; i++) {
    if(Left[i] != 0) return(true);
    if(Right[i] != 0) return(true);
  }
  return(false);
}

int main()
{
  while(cin >> N >> L, N) {
    memset(Left, 0, sizeof(Left));
    memset(Right, 0, sizeof(Right));
    for(int i = 0; i < N; i++) {
      char c;
      int d;
      cin >> c >> d;
      if(c == 'L') Left[d] = i + 1;
      else Right[d] = i + 1;
    }
    int last, time;
    for(time = 0; Check(); ++time) {
      for(int i = L; i > 0; i--) {
        Right[i] = Right[i - 1];
      }
      for(int i = 0; i < L; i++) {
        Left[i] = Left[i + 1];
      }
      if(Right[L] > 0) last = Right[L];
      if(Left[0] > 0) last = Left[0];
      for(int i = 1; i < L; i++) {
        if(Left[i] > 0 && Right[i] > 0) swap(Left[i], Right[i]);
      }
    }
    cout << --time << " " << last << endl;
  }
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

	char[][] map = new char[][]{
		{'.','.','r','r','.','.','.','.'},
		{'.','.','r','r','.','.','.','.'},
		{'g','g','y','y','b','b','w','w'},
		{'g','g','y','y','b','b','w','w'},
		{'.','.','o','o','.','.','.','.'},
		{'.','.','o','o','.','.','.','.'},	
	};
	
	char tempA, tempB;
	
	void rotate90(int y, int x){
		tempA = map[y][x];
		map[y][x] = map[y+1][x];
		map[y+1][x] = map[y+1][x+1];
		map[y+1][x+1] = map[y][x+1];
		map[y][x+1] = tempA;
	}

	void solve(){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNext()){
			String s = sc.next();
			
			for(int i=0;i<s.length();i++){
				//U
				if(s.codePointAt(i)==85){
					tempA = map[2][0];
					tempB = map[2][1];
					for(int j=0;j<6;j++) map[2][j] = map[2][j+2];
					map[2][6] = tempA;
					map[2][7] = tempB;
					rotate90(0,2);
				}
				//D
				else if(s.codePointAt(i)==68){
					tempA = map[3][6];
					tempB = map[3][7];
					for(int j=0;j<6;j++) map[3][7-j] = map[3][5-j];
					map[3][0] = tempA;
					map[3][1] = tempB;
					rotate90(4,2);
				}
				//R
				else if(s.codePointAt(i)==82){
					tempA = map[0][3];
					tempB = map[1][3];
					for(int j=0;j<4;j++) map[j][3] = map[j+2][3];
					map[4][3] = map[3][6];
					map[5][3] = map[2][6];
					map[3][6] = tempA;
					map[2][6] = tempB;
					rotate90(2,4);
				}
				//L
				else if(s.codePointAt(i)==76){
					tempA = map[4][2];
					tempB = map[5][2];
					for(int j=0;j<4;j++) map[5-j][2] = map[3-j][2];
					map[0][2] = map[3][7];
					map[1][2] = map[2][7];
					map[3][7] = tempA;
					map[2][7] = tempB;
					rotate90(2,0);
				}
				//F
				else if(s.codePointAt(i)==70){						
					tempA = map[1][2];
					tempB = map[1][3];
					map[1][2] = map[3][1];
					map[1][3] = map[2][1];
					map[3][1] = map[4][3];
					map[2][1] = map[4][2];
					map[4][3] = map[2][4];
					map[4][2] = map[3][4];
					map[2][4] = tempA;
					map[3][4] = tempB;			
					rotate90(2,2);
				}
				//B
				else if(s.codePointAt(i)==66){						
					tempA = map[0][2];
					tempB = map[0][3];
					map[0][2] = map[2][5];
					map[0][3] = map[3][5];
					map[2][5] = map[5][3];
					map[3][5] = map[5][2];
					map[5][3] = map[3][0];
					map[5][2] = map[2][0];
					map[3][0] = tempA;
					map[2][0] = tempB;
					rotate90(2,6);
				}	
			}
			for(int k=0;k<6;k++){
				for(int j=0;j<8;j++){
					System.out.print(map[k][j]);
				}
				System.out.println();
			}
		}
	}
	
	
	public static void main(String[] args) {
		new Main().solve();
	}	
}

Measured memory_bytes: 17332
#include<bits/stdc++.h>
using namespace std;
#define sz(a) int((a).size())
#define int long long
#define all(c) c.begin(), c.end()
#define FAST ios_base::sync_with_stdio(false) , cin.tie(NULL);
#define pb push_back
#define F first
#define S second
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define one(x) cout<<#x<<" : "<<x<<endl;
#define two(x,y) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<endl;
#define three(x,y,z) cout<<#x<<" : "<<x<<" , "<<#y<<" : "<<y<<" , "<<#z<<" : "<<z<<endl;
#define PI acos(-1)
const int M = 1000000007;
const int N=3e5+5;


signed main()
{
    int n ,i ,j;
    cin >> n;
    vector< int > a(n);
    for(i=0 ;i<n ;i++)
    {
        cin >> a[i];
    }
    sort(all(a));
    int ans=0;
    for(i=n-1 ; i>=0 ;i--)
    {
        for(j=i-1 ; j>=0 ; j--)
        {
            int diff = a[i] - a[j] +1;
            int lb = lower_bound(a.begin() , a.end() , diff) - a.begin();
            if(j > lb)
            ans+=j-lb;
        }
    }
    cout<<ans<<endl;

}




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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0;}
template<class T>bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0;}

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

const int limit = 200010;
ll a[limit], b[limit];
const ll inf = 1LL << 60;


multiset<ll> positive, negative;
ll a_total = 0LL, p_total = 0LL;

int n, q;

inline void add(int i) {
	a_total += a[i];
	if (i == 0 or i == 2 * n - 1) return;
	const ll val = b[i] - a[i];
	if (val >= 0) {
		positive.insert(val);
		p_total += val;
	} else {
		negative.insert(val);
	}
}

inline void del(int i) {
	a_total -= a[i];
	if (i == 0 or i == 2 * n - 1) return;
	const ll val = b[i] - a[i];
	if (val >= 0) {
		auto it = positive.find(val);
		positive.erase(it);
		p_total -= val;
	} else {
		auto it = negative.find(val);
		negative.erase(it);
	}
}

int main(void) {
	cin >> n >> q;

	rep(i, 2 * n) cin >> a[i];
	rep(i, 2 * n) cin >> b[i];

	rep(i, 2 * n) a_total += a[i];

	rep(i, 1, 2 * n - 1) {
		const ll val = b[i] - a[i];
		if (val >= 0) {
			positive.insert(val);
			p_total += val;
		} else {
			negative.insert(val);
		}
	}


	rep(loop, q) {
		int p;
		ll x, y;
		cin >> p >> x >> y;

		del(p - 1);
		a[p - 1] = x, b[p - 1] = y;
		add(p - 1);

		ll ans = -inf;
		if (positive.size() % 2 == 0) {
			chmax(ans, a_total + p_total);
		} else {
			const ll mmax = *prev(end(negative));
			const ll pmin = *begin(positive);
			chmax(ans, a_total + p_total + mmax);
			chmax(ans, a_total + p_total - pmin);
		}

		cout << ans << endl;
	}

	return 0;
}

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

using namespace std;

void solve()
{
    int sum=0, max=0;
    for(int i = 0; i < 3; i++) {
        int v;
        cin >> v;
        if(v > max) max = v;
        sum += v;
    }
    int ans = sum - max;
    cout << ans << endl;
    return;
}

int main()
{
    solve();
    return 0;
}

Measured memory_bytes: 256
n,m=map(int,input().split())

g = [[] for _ in range(n)]
for i in range(m):
	x,y,z=map(int,input().split())
	g[x-1].append(y-1)
	g[y-1].append(x-1)

check = [False]*n

cnt=0
import queue
for i in range(n):
	if check[i]:
		continue
	cnt+=1
	check[i]=True
	q=queue.Queue()
	q.put(i)

	while not q.empty():
		now=q.get()
		for ne in g[now]:
			if check[ne]:
				continue
			check[ne]=True
			q.put(ne)

print(cnt)

Measured memory_bytes: 93852
#include <iostream>

using namespace std;

const int MAX = 1010;
int factors[MAX];

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

  int tmp;
  for (int i = 2; i <= N; i++) {
    tmp = i;
    int j = 2;
    while (j <= i) {
      if (tmp % j == 0) {
	factors[j]++;
	tmp /= j;
      }
      else {
	j++;
      }
    }
  }

  /*
  for (int i = 0; i < N; i++) {
    cout << factors[i] << ' ';
  }
  */

  long long ans = 1;
  for (int i = 0; i <= N; i++) {
    if (factors[i] != 0) {
      ans *= (factors[i] + 1);
      ans %= 1000000007;
    }
  }

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


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


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

struct edge {int to; ll cost; };

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

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

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}
 
int main(){
  int x;
  cin >> x;
  x -= 400;
  x /= 200;
  int ans = 8 - x;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3660
#include <cstdio>

int main() {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    if(a <= b&&b <= c) {
        printf("%d %d %d\n",a,b,c);
        return 0;
    }
    else if(a <= c&&c <= b) {
        printf("%d %d %d\n",a,c,b);
        return 0;
    }
    else if(b <= a&&a <= c) {
        printf("%d %d %d\n",b,a,c);
        return 0;
    }
    else if(c <= a&&a <= b) {
        printf("%d %d %d\n",c,a,b);
        return 0;
    }
    else if(b <= c&&c <= a) {
        printf("%d %d %d\n",b,c,a);
        return 0;
    }
    else if(c <= b&&b <= a) {
        printf("%d %d %d\n",c,b,a);
        return 0;
    }
}


Measured memory_bytes: 2744
#line 2 "../../library/template.hpp"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pl = pair<ll, ll>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define rep3(i, l, r) for(ll i = l; i < (ll)r; i++)
#define per(i, n) for(ll i = (ll)n-1; i >= 0; i--)
#define per3(i, l, r) for(ll i = (ll)r-1; i >= (ll)l; i--)
#define all(v) begin(v), end(v)
template<class T, class U> inline void cmax(T &a, U b) { if (a < b) a = b; }
template<class T, class U> inline void cmin(T &a, U b) { if (a > b) a = b; }
constexpr char el = '\n';
template<class T, class U> ostream &operator<<(ostream &os, const pair<T, U> &p) { os << p.first << " " << p.second; return os; }
template<class T, class U> istream &operator>>(istream &is, pair<T, U> &p) { is >> p.first >> p.second; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { rep(i, v.size()) os << v[i] << (i+1 != v.size() ? " " : ""); return os; }
template<class T> istream &operator>>(istream &is, vector<T> &v) { for(T &i : v) is >> i; return is; }
struct IoSetup {
  IoSetup() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); cerr << fixed << setprecision(15); }
} io_setup;
#line 2 "d.cpp"

int main() {
  ll n;
  cin >> n;
  vl a(n);
  cin >> a;

  vl dp(n+1);
  dp[0] = 1000;
  rep(i, n) {
    dp[i+1] = dp[i];
    rep(j, i) {
      ll cnt = dp[j+1]/a[j];
      cmax(dp[i+1], dp[j+1] - cnt*a[j] + cnt*a[i]);
    }
  }

  cout << dp[n] << el;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 100;
const int MOD = 1e9 + 7;
int n, m, x, y;
long long dp[maxn][maxn];
int a[maxn][maxn];
string str;
int main()
{
    cin>>n>>m;
    for(int i = 0; i < n; i++){
        cin>>str;
        for(int j = 0; j < m; j++) a[i][j] = str[j];
    }
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            if(a[i][j] == '#') continue;
            //cout<<a[i][j];
            if(i-1 >= 0) (dp[i][j] += dp[i-1][j]) %= MOD;
            if(j-1 >= 0) (dp[i][j] += dp[i][j-1]) %= MOD;
        }
    }
    cout<<dp[n-1][m-1]<<endl;
}


Measured memory_bytes: 13568
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
int n,f,s[14][8],t,h,ans;
int main()
{
  scanf("%d%d",&n,&f);
  for(int i=1;i<=11;i++)
    for(int j=1;j<=7;j++)
    {
      t++;
      s[i][j]=t;
    }
  for(int i=1;i<=11;i++)
    for(int j=1;j<=7-3+1;j++)
    {
      t=0;
	  for(int k=0;k<3;k++)
        for(int l=0;l<3;l++)
          t+=s[(i+k-1)%11+1][j+l];
      if(t%11==f)h++;
    }
  ans+=max(0,(n/11-1))*h;
  if(n/11>0)n-=(n/11-1)*11;
  for(int i=1;i<=n-3+1;i++)
    for(int j=1;j<=7-3+1;j++)
    {
      t=0;
	  for(int k=0;k<3;k++)
        for(int l=0;l<3;l++)
          t+=s[(i+k-1)%11+1][j+l];
      if(t%11==f)ans++;
    }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		String str = sc.next();

        char[] str_a = str.toCharArray();
        char[] str_1 = new char[4];
        char[] str_2 = new char[str.length()-4];
        for (int i=0;i<4;i++){
        	str_1[i] = str_a[i];
        }
        for (int i=4;i<str_a.length;i++){
        	str_2[i-4] = str_a[i];
        }
        String a = new String(str_1);
        String b = new String(str_2);
        String c = a+' '+b+'\n';
        System.out.println(a+" "+b);
	}

}

Measured memory_bytes: 9684
//
// Created by Mahmoud Rashad on 11/27/19.
//

#include <bits/stdc++.h>


using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<pair<ii, ii>> vii;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//    freopen("output.out", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(10), cout << fixed;

    int n;
    cin >> n;
    map<int, int> mp;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        mp[x]++;
    }

    int ans = 0;
    for (auto it : mp) {
        if (it.second >= it.first)
            ans += it.second - it.first;
        else
            ans += it.second;
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 4736
import sys
sys.setrecursionlimit(10**6)

def main():
    n = input().rstrip()
    k = int(input())
    dp = [[[0 for equal_n      in range(2)]
              for cnt_not_zero in range(k + 1)]
              for digit        in range(len(n) + 1)]
    dp[0][0][1] = 1
    for digit in range(len(n)):#桁
        for cnt_not_zero in range(k+1):#非0の個数
            for equal_n in reversed(range(2)):#nと一致しているかn未満か
                std_val = int(n[digit])
                for target_val in range(10):
                    target_digit = digit + 1
                    target_cnt_not_zero = cnt_not_zero
                    if target_val != 0:
                        target_cnt_not_zero += 1
                    if target_cnt_not_zero > k:
                        continue
                    target_equal_n = equal_n
                    if equal_n == 1:
                        if target_val > std_val:
                            continue
                        if target_val < std_val:
                            target_equal_n = 0
                    dp[target_digit][target_cnt_not_zero][target_equal_n] += dp[digit][cnt_not_zero][equal_n]
    print(dp[len(n)][k][1] + dp[len(n)][k][0])

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if(a < b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if(a > b){ a = b; return 1; } return 0; }
int main()
{
  int h,w; cin >> h >> w;
  int n; cin >> n;
  vector<set<int>> st(w);
  rep(i,n) {
    int x,y; cin >> x >> y;
    x--; y--;
    st[y].insert(x);
  }

  rep(i,w) {
    st[i].insert(h);
  }

  int j = 0;
  int res = 1e+9;
  rep(i,w) {
    auto it = st[i].lower_bound(j);
    while(*it == j) {
      it++; j++;
      if(j >= h) break;
    }
    if(j >= h) {
      chmin(res, h);
      break;
    }
    chmin(res, *it);
    //    cout << i << ":" << j << "\n";
    j++;
  }

  cout << res << "\n";
  
  return 0;
}


Measured memory_bytes: 28416
debug = false
function log() {
  if (debug) {
    var arr = []
    for (var i = 0; i < arguments.length; i++) {
      arr.push(arguments[i])
    }
    console.log(arr.join(', '))
  }
}

function Main(input) {
  lines = input.split("\n")
  f = lines[0].split(" ")
  N = f[0]
  A = f[1] * 1
  B = f[2] * 1
  C = f[3] * 1
  D = f[4] * 1
  s = lines[1]
  log(N, A, B, C, D, s)

  bool = true
  if (C > D) {
    end = D
    s2 = s
    if (s[D - 2] == '.' && s[D] == '.') {
    } else if (D - B == 1 && s[D - 3] == '.') {
    } else {
      if (s[D - 2] == '#') {
        log(s2, s2[D - 1])
        s2[D - 1] = '#'
        s2 = s2.slice(0, D - 1) + '#' + s2.slice(D)
      }
      log(s2)
      str = s2.slice(B - 2, end)
      log(str, bool)
      bool = bool && (/\.\.\./).test(str)
      log(str, bool)
    }
  }
  str = s.slice(A - 1, C)
  bool = bool && !(/##/).test(str)
  log(str, bool)
  str = s.slice(B - 1, D)
  bool = bool && !(/##/).test(str)
  log(str, bool)

  ans = bool ? 'Yes' : 'No'
  console.log(ans)
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main(void) {
    int rate[9] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200, 4800}, n, zohe = 0, ehoz = 0;
    bool color[8] = {};
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        for (int i = 0; i < 9; i++) {
            if (i == 8) {
                zohe++;
                break;
            }
            if (a < rate[i]) {
                color[i] = true;
                break;
            }
        }
    }
    for (int i = 0; i < 8; i++) if (color[i]) ehoz++;
  	if (ehoz == 0) cout << 1 << ' ' << zohe << endl;
    else cout << ehoz << ' ' << ehoz + zohe << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define itn int
#define gI gi
#define int long long 

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int mod = 1000000007;

int n, f[5000003], k, len, ans, c[103][103], dp[10003][5][3];
char s[10003];
string ss;

inline int qpow(int x, int y)
{
	int res = 1;
	while (y)
	{
		if (y & 1) res = (res * x) % mod;
		x = x * x % mod, y >>= 1;
	}
	return res % mod;
}

inline int getc(int x, int y)
{
	return f[x] * qpow(f[y], mod - 2) % mod * qpow(f[x - y], mod - 2) % mod;
}

signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	int r1 = gi(), c1 = gi(), r2 = gi(), c2 = gi();
	n = max(c1, c2) + r2 + 2;
	f[0] = 1;
	for (int i = 1; i <= n; i+=1) f[i] = (f[i - 1] * i) % mod;
	for (int i = r1; i <= r2; i+=1) ans = (ans + getc(i + c2 + 1, i + 1)) % mod;
	for (int i = r1; i <= r2; i+=1) len = (len + getc(i + c1, i + 1)) % mod;
	printf("%lld\n", (ans - len + mod) % mod);
	return 0;
}



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

int main() {
  int N, K;
  int x[N];
  cin >> N >> K;
  REP(i, N) cin >> x[i];

  int ans = 0;
  REP(i, N) {
    int m = min(x[i], abs(K - x[i]));
    ans += m * 2;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &&x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define INSEG(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void PSUM(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(false);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

bool a_less_than_b(const string &a, const string &b) {
    if (SZ(a) != SZ(b)) return SZ(a) < SZ(b);
    return a < b;
}
signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> A(M);
    cin >> A;
    vector<int> need = {INF, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    vector<string> dp(N + 1);
    dp[N] = "~";
    REPR(i, N) {
        REPR(j, M - 1) {
            int nxt = i - need[A[j]];
            char x = A[j] + '0';
            string val = dp[i] + x;
            if (nxt >= 0 && a_less_than_b(dp[nxt], val)) dp[nxt] = val;
        }
    }
    cout << dp[0].substr(1, SZ(dp[0]) - 1) << endl;
    return (0^_^0);
}



Measured memory_bytes: 45440
import bisect

n = int(input())
l = list(int(x) for x in input().split())
l.sort()
ans = 0
for i in range(n):
    for j in range(i+1, n):
        key = bisect.bisect_left(l, l[j]-l[i]+1)
        ans += max([0, i-key])
print(ans)

Measured memory_bytes: 3188