akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 30;
// clang-format on

int N;
int x[MAX_N], y[MAX_N];

void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

int cnt = 0;
double sum = 0;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> N;
  REP(i,N) cin >> x[i] >> y[i];

  foreach_permutation(N, [](int *indexes){
      cnt++;
    for(int i = 0; i < N - 1; i++) {
      int s = indexes[i], t = indexes[i+1];
      sum += sqrt(pow(x[s] - x[t],2) + pow(y[s] - y[t],2));
    }
  });

  printf("%.9f\n", sum / cnt);

  return 0;
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int l,r; cin>>l>>r;
	bool yes=false;
	if(r-l>=2){
		int limit=min(r,l+673);
		for(int i=l;i<=limit;++i){
			if(i%673==0)yes=true;
		}
	}
	if(yes)cout<<0;
	else{
		size_t ans=INT_MAX;
		size_t limit=min(r,l+2019);
		for(size_t i=l;i<=limit;++i){
			for(size_t j=i+1;j<=limit;++j){
				ans=min(ans,i*j%2019);
			}
		}cout<<ans<<"\n"s;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;


int main(){
  int n,m; cin >> n >> m;
  vector<int> x(m);
  rep(i,m){cin>>x[i];}
  if(n>=m){ cout << 0 << endl; return 0;}
  
  sort(x.begin(),x.end());
  vector<int> d(m);
  rep(i,m-1){
    d[i] = x[i+1]-x[i];
  }
  sort(d.begin(),d.end());
  
  ll ans = accumulate(d.begin(),d.begin()+m-n+1,0); 
  cout << ans << endl;

  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,a=0,w=0,t=0,r=0;
    cin>>n;
    while(n--)
    {
        string s;
        cin>>s;
        if(s=="AC")
        {
            a++;
        }
         else if(s=="WA")
        {
            w++;
        }
        else if(s=="TLE")
        {
            t++;
        }
        else if(s=="RE")
        {
            r++;
        }
    }
    cout<<"AC"<<" "<<"x"<<" "<<a<<endl;
     cout<<"WA"<<" "<<"x"<<" "<<w<<endl;
      cout<<"TLE"<<" "<<"x"<<" "<<t<<endl;
       cout<<"RE"<<" "<<"x"<<" "<<r<<endl;
}


Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <map>
using namespace std;
#define ll long long

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*1LL*c,max(a*1LL*d,max(b*1LL*c,b*1LL*d))); 
}


Measured memory_bytes: 3192
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		List<Integer> list = new ArrayList();
		for(int i=0;i<N; i++) {
			list.add(Integer.parseInt(sc.next()));
		}
		int total = 0;

		for(int i=0; i<N-1; i++) {
			for(int j=i+1; j<N; j++) {
				total += list.get(i) * list.get(j);
			}
		}
		System.out.println(total);

	}
}


Measured memory_bytes: 21844
#include<iostream>
#include<algorithm>

using namespace std;

void print(vector<int> v)
{
    cout<<v[0];
    for(int i=1;i<v.size();i++)
    {
        cout<<" "<<v[i];
    }
    cout<<endl;
}

int main()
{
    int n;
    cin>>n;
    vector<int > v;
    for(int i=1;i<=n;i++)
    {
        v.push_back(i);
    }
    
    do
    {
        print (v);
    }while(next_permutation(v.begin(),v.end()));
}


Measured memory_bytes: 3152
N, K = map(int, input().split())

p = list(map(int,input().split()))

sum_p_max = sum(p[0:K])
sum_i = sum(p[0:K])

for i in range(1, N-K+1):
    sum_i += p[i+K-1] - p[i-1]
    if sum_p_max < sum_i:sum_p_max = sum_i
print((sum_p_max+K)/2)

Measured memory_bytes: 25060
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
 
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N, Y;
  cin >> N >> Y;
 
  for ( int i = 0; i <= N; i++ ) {
    for ( int j = 0; j <= N; j++ ) {
      if ( i+j > N ) break;
      int k = N-i-j;
      if ( i*10000 + j*5000 + k*1000 == Y ) {
	cout << i << " " << j << " " << k << endl;
	return 0;
      }
    }
  }

  cout << -1 << " " << -1 << " " << -1 << endl;
  
  return 0;
}


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

mw = 0
mh = 0
for _ in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        mw = max(mw, x)
    elif a == 2:
        w = min(w, x)
    elif a == 3:
        mh = max(mh, y)
    elif a == 4:
        h = min(h, y)

print((w-mw)*(h-mh) if mw <= w and mh <= h else 0)


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

using namespace std;

typedef long long llint;

const int MAXN = 100005;

llint n, k;
llint a[MAXN], p[MAXN], s[MAXN];

llint sum (int x, int y) {
    if (x > y) return 0;
    return p[y] - p[x-1];
}

llint sum2 (int x, int y) {
    if (x > y) return 0;
    return s[y] - s[x-1];
}

int main () {
    cin >> n >> k;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        p[i] = a[i] + p[i-1];
        s[i] = max(a[i], 0LL) + s[i-1];
    }
    llint sol = 0;
    for (int i=1; i+k-1 <=n; i++) {
        llint res = sum2(1, i-1) + max(0LL, sum(i, i+k-1)) + sum2(i+k, n);
        sol = max(sol, res);
    }
    cout << sol;
    return 0;
}


Measured memory_bytes: 2560
def exchange(_A, _B, _C, _count):
    if _A % 2 == 1 or _B % 2 == 1 or _C % 2 == 1:
        return _count

    _count += 1
    tmp1 = _A / 2
    tmp2 = _B / 2
    tmp3 = _C / 2
    return exchange(tmp2 + tmp3, tmp1 + tmp3, tmp1 + tmp2, _count)


A, B, C = list(map(int, input().split()))
if A % 2 == 0 and A == B and B == C:
    print("-1")
else:
    count = 0
    ans = exchange(A, B, C, count)

    print(ans)


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

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

  vector<int> A(N);
  rep(i, N) cin >> A[i];

  int a = N - K;
  int b = K - 1;
  int g = (a + b - 1) / b + 1;

  cout << g << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
int k;
cin>>k;
string s;
cin>>s;
string c="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
for(int i=0; i<s.length(); ++i)
{
int y=s[i]-'A';
cout<<c[y+k];
}
return 0;
}

Measured memory_bytes: 256
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    N = input.split("\n")[0];
    H = input.split("\n")[1].split(" ").map(Number);
    answer = 0;
    tmpmax = 0;
    
    for(i = 0; i< H.length ; i++){
        if(tmpmax <= H[i]){
            tmpmax = H[i];
            answer +=1;
            
        }
    }
    console.log(answer);
}
    


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter,mul
from fractions import gcd
from functools import reduce
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

#https://atcoder.jp/contests/caddi2018/tasks/caddi2018_a

n,p=mii()

# N: 素因数分解する数
#リストで返す
res = []
x = p

y = 2
while y*y <= x:
    while x % y == 0:
        res.append(y)
        x //= y
    y += 1
if x > 1:
    res.append(x)

m=Counter(res)

ans=1
for key ,val in m.items():
    if val>=n:
        ans*=key**(val//n)

print(ans)


Measured memory_bytes: 63468
#include<bits/stdc++.h>
#include <iomanip>
#define LL long long
using namespace std;
inline LL read(){
	LL x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
#define MN 1005
#define T 1003
long long n,xs,ys,xt,yt,x[MN],y[MN],r[MN];
int top,tail;
bool vis[MN];
long double d[MN],mp[MN][MN];
int q[MN*MN];
long double pw(long long x){return x*x;}
long double find_ds(int xx,int yy,int rr){long double res=sqrt(pw(xx-xs)+pw(yy-ys))-rr;if(res>0) return res;return 0;}
long double find_dc(int i,int j){long double res=sqrt(pw(x[i]-x[j])+pw(y[i]-y[j]))-r[i]-r[j];if(res>0) return res;return 0;}
long double find_dt(int i){long double res=sqrt(pw(x[i]-xt)+pw(y[i]-yt))-r[i];if(res>0)return res;return 0;}
void spfa(){
	for(top=1;top<=tail;vis[q[top++]]=true)
		for(int i=1;i<=n;i++)
			if(i!=q[top]&&mp[i][q[top]]+d[q[top]]<d[i]){
				d[i]=mp[i][q[top]]+d[q[top]];
				if(vis[i]) q[++tail]=i,vis[i]=false;
			}
}
int main(){
	xs=read(),ys=read(),xt=read(),yt=read();
	n=read();
	for(int i=1;i<=n;i++) x[i]=read(),y[i]=read(),r[i]=read(),d[i]=find_ds(x[i],y[i],r[i]),q[++tail]=i;
	for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) if(i!=j) mp[i][j]=find_dc(i,j);
	spfa();
	d[T]=find_ds(xt,yt,0);
	for(int i=1;i<=n;i++) if(d[T]>find_dt(i)+d[i]) d[T]=find_dt(i)+d[i];
	cout<<fixed<<setprecision(10)<<d[T]<<endl;
	return 0;
}

Measured memory_bytes: 18944
package main

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

func newScanner() *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	// buf := make([]byte, 10000)
	// scanner.Buffer(buf, 1000000)
	return scanner
}

func scanInt() int {
	if sc.Scan() {
		t := sc.Text()
		if v, err := strconv.Atoi(t); err == nil {
			return v
		}
		panic(fmt.Sprintln("Could't scan int from input", t))
	}
	panic(sc.Err())
}

func scanInts(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = scanInt()
	}
	return a
}

var sc *bufio.Scanner = newScanner()

func main() {
	n := scanInt()
	a := scanInts(n)

	var r, sum, res int
	for i := 0; i < n; i++ {
		for r < n && sum^a[r] == (sum+a[r]) {
			sum += a[r]
			r++
		}
		res += r - i
		if r == i {
			res++
		} else {
			sum -= a[i]
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 3840
n = int(input())
a = list(map(int,input().split()))

a = sorted(a, reverse = True)
x = []
y = []
ans = 0
flg = 0
for i in a:
    if flg == 0:
        ans +=i
        flg = 1
    else:
        ans -=i
        flg = 0
print(ans)

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

int main(){
    string s;
    cin >> s;
    string ss = "CODEFESTIVAL2016";
    int sum = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] != ss[i]) sum++;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <numeric>
#include <string.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const long long  INFL = 1e18;
const int MOD = 1000000007;

void solve() {
	string s; cin >> s;
	set<char> cnt_s;
	int cnt = 1;
	for (unsigned int i = 0; i < s.length(); ++i) {
		cnt_s.insert(s[i]);
	}
	char cmp_a = s[0];
	for (unsigned int i = 1; i < s.length(); ++i) {
		char cmp_b = s[i];
		if (cmp_a == cmp_b) cnt++;
	}
	if (cnt_s.size() == 2 && cnt == 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return;
}

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

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

#ifdef DEBUG
    #include "debug.h"
    #define DEB
    #define dump(...)                                                              \
        DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
                << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
                << endl                                                            \
                << "    ",                                                         \
            dump_func(__VA_ARGS__)
#else
    #define DEB if (false)
    #define dump(...)
#endif


// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

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

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

#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
#define ALL(v) (v).begin(), (v).end()
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
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; }

//*
#define mod 1000000007 /*/
#define mod 998244353 //*/

typedef pair<int, int> P;
#define INF (1LL<<60)


void solve(){
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}


signed main(){
    cout << fixed << setprecision(18);
    cerr << fixed << setprecision(18);
    solve();
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define INF (1LL << 60)

int main() {
    int N;
    cin >> N;
    vector<int> a(N), b(N);
    for(int i=0; i<N; ++i) cin >> a[i];
    for(int i=0; i<N; ++i) cin >> b[i];

    long long cost[51][51];

    for(int i=0; i<=50; ++i) {
        for(int j=0; j<=50; ++j) {
            cost[i][j] = INF;
        }
    }
    
    for(int i=0; i<=50; ++i) {
        cost[i][i] = 0;
        for(int k=1; k<=50; ++k) {
            cost[i][i % k] = min(cost[i][i % k], (1LL << k));
        }
    }

    long long res = 0;
    for(int k=50; k>0; --k) {
        
        for(int l=0; l<=50; ++l) {
            for(int i=0; i<=50; ++i) {
                for(int j=0; j<=50; ++j) {
                    cost[i][j] = min(cost[i][j], cost[i][l] | cost[l][j]);
                }
            }
        }

        long long tmp = 0;
        for(int i=0; i<N; ++i) {
            if(cost[a[i]][b[i]] == INF) {
                cout << -1 << endl;
                return 0;
            }
            tmp |= cost[a[i]][b[i]];
        }
        if((tmp >> k) & 1) {
            res += (1LL << k);
            for(int i=0; i<=50; ++i) cost[i][i % k] = 0;
        }
    }

    cout << res << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

void Main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  vector<int> idx(n);
  rep(i, n) {
    p[i]--;
    idx[p[i]] = i;
  }

  set<int> s;
  ll ans = 0;
  for (int x = n - 1; x >= 0; --x) {
    int i = idx[x];
    s.insert(i);
    vector<int> l(2, -1);
    {
      auto it = s.find(i);
      rep(j, 2) {
        if (it == s.begin()) break;
        --it;
        l[j] = *it;
      }
    }
    vector<int> r(2, n);
    {
      auto it = s.find(i);
      rep(j, 2) {
        ++it;
        if (it == s.end()) break;
        r[j] = *it;
      }
    }
    ans += (ll)(i - l[0]) * (r[1] - r[0]) * (x + 1);
    ans += (ll)(r[0] - i) * (l[0] - l[1]) * (x + 1);
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 5760
import java.util.*;

public class Main
{
    public static void main(String[] args)
    {
        //long start = System.currentTimeMillis();
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        long[] cSum = new long[n+1];
        cSum[0] = 0;
        for (int i = 0;i<n;++i)
        {
            a[i] = sc.nextLong();
            cSum[i+1] = cSum[i] + a[i];
        }
        sc.close();

        cSum[n] = cSum[n-1] + a[n-1];
        //for (int i = 0;i<cSum.length;++i) System.err.println(cSum[i]);

        long sum = 0;
        long mod = (long) Math.pow(10,9)+7;

        for (int i = 0;i<n;++i)
        {
            long tmp = (cSum[n] - cSum[i+1]) % mod;
            sum += a[i] * tmp;
            sum %= mod;
        }

        System.out.println(sum);
//        long end = System.currentTimeMillis();
//        System.err.println((end-start)+"ms");
    }
}

Measured memory_bytes: 52744
#include<stdio.h>
#define N 100
#define WHITE 0
#define GRAY 1
#define BLACK 2


int n,M[N][N];
int color[N],d[N],f[N],tt;

void dfs_visit(int u){
  int v;
  color[u]=GRAY;
  d[u]=++tt;
  for(v=0;v<n;v++){
    if(M[u][v]==0) continue;
    if(color[v]==WHITE){
      dfs_visit(v);
    }
  }
  color[u]=BLACK;
  f[u]=++tt;

}

void dfs(){
  int u;
  for(u=0;u<n;u++)color[u]=WHITE;
  tt=0;

  for(u=0;u<n;u++){
    if(color[u]==WHITE)dfs_visit(u);
  }
  for(u=0;u<n;u++){
    printf("%d %d %d\n",u+1,d[u],f[u]);
  }
}


int main() {
  int u,v,k,i,j;

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

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    u--;
    for(j=0;j<k;j++){
      scanf("%d",&v);
      v--;
      M[u][v]=1;
    }
  }

  dfs();

  return 0;

}



Measured memory_bytes: 2048
# cs: c nnected switches
n, m = map(int, input().split())

def get_connected_switches():
    # k s1 s2 .. sn
    lst = list(map(int, input().split()))
    lst.pop(0) # k is not use
    return list(map(lambda d: 1<<(d-1), lst ))

# cs: connected switches
cs = [get_connected_switches() for _ in range(m)]
ps = list(map(int, input().split()))

# bit全探索(0: すべてoffは不要)
ans = 0
# on: 0:消えてる、1:点いてる
# 10: 1 2  3   4 
# 0b: 1 10 11, 100..
for on in range(2**n):
    ok = True
    for i in range(m):
        ct = 0
        for s in cs[i]:
            if s&on: ct += 1
        if ct%2 != ps[i]:
            ok = False
    if ok:
        ans += 1
print(ans)


Measured memory_bytes: 9072
#include "bits/stdc++.h"

using namespace std;

//int N,M,K,L,R,H,W;
long long int N,M,K,L,R,H,W;

//constexpr long long int MOD=1000000007;
constexpr  int MOD=1000000007;
//constexpr int MOD=998244353;
//constexpr long long int MOD=998244353;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin>>s;
	if(s=="SAT")cout<<1<<endl;
	if(s=="FRI")cout<<2<<endl;
	if(s=="THU")cout<<3<<endl;
	if(s=="WED")cout<<4<<endl;
	if(s=="TUE")cout<<5<<endl;
	if(s=="MON")cout<<6<<endl;
	if(s=="SUN")cout<<7<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>
using namespace std;
const int N = 100;
const int WHITE = 0;
const int GRAY = 1;
const int BLACK = 2;

int n,M[N][N];
int color[N],d[N],f[N],tt;
int nt[N];

// u?????£??\??????v?????????????????????
int next(int u){
    for (int v = nt[u]; v < n ; v++) {
        nt[u] = v +1;
        if(M[u][v]) return v;
    }
    return -1;
}

//with stack

void dfs_visit (int r){
    for (int i = 0; i < n ; ++i) nt[i] = 0;

    stack<int> S;
    S.push(r);
    color[r] = GRAY;
    tt ++; d[r] = tt;

    while(! S.empty()){
        int u = S.top();
        int v = next(u);
        if( v != -1){
            if(color[v] == WHITE) {
                color[v] = GRAY;
                d[v] = ++tt;
                S.push(v);
            }
        }else{
            S.pop();
            color[u] = BLACK;
            f[u] = ++ tt;
        }
    }
}

void dfs(){
    int u;
    for (u = 0; u < n; ++u) {
        color[u] = WHITE;
    }
    tt = 0;

    for (int u = 0; u < n ; ++u) {
        //????¨???????u????§??????¨????????±???????????¢?´¢
        if(color[u] == WHITE) dfs_visit(u);
    }
    for (int u = 0; u < n ; ++u) {
        cout << u+1 << " " << d[u] << " " << f[u] << endl;
    }
}

int main(){
    int u,v,k;
    
    for (int i = 0; i < n ; ++i) {
        for (int j = 0; j < n ; ++j) {
         M[i][j] = 0;   
        }
    }
    
    cin >> n;
    for (int i = 0; i < n ; ++i) {
        cin >> u >> k;
        u --;
        for (int j = 0; j < k ; ++j) {
            cin >> v;
            v --;
            M[u][v] = 1;
        }
    }
    dfs();
    return 0;
}

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


int main(int argc, char const *argv[])
{
    string s; 
    cin >> s; 
    if(s[0] != 'A'){
        cout << "WA"; 
        return 0; 
    }
    int n = s.size(); 
    int index = -1; 
    bool ok = false; 
    for(int i = 2; i< n - 1; ++i){
        if(s[i] == 'C') {
            ok = true;
            index = i; 
            break;  
        }
    }
    if(!ok) {
        cout << "WA";
        return 0;
    }
    ok = true;  
    for(int i = 1; i<n; ++i){
        if(i != index){
            if ((int)s[i] > (int)'z' || (int)s[i] < (int)'a')
            {
                ok = false; 
                break; 
            }
        }
    }
    if (!ok)
    {
        cout << "WA";
        return 0;
    }
    cout << "AC"; 

    return 0; 
}


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

//#define int long long
//using ll = boost::multiprecision::cpp_int;
using ll = long long;
//constexpr int INF = 1e9;//INT_MAX=1<<31-1=2147483647
constexpr ll INF = (ll)1e18;//1<<63-1=9223372036854775807
constexpr ll MOD = (ll)1e9 + 7;
constexpr double EPS = 1e-9;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
#ifdef LOCAL_ENV
	#define debug(var) std::cout<<#var" = "<<var<<std::endl
#else
	#define debug(var)
#endif
#define p(var) std::cout<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)
#define repeq(i, n) for(ll i=1, i##_length=(n); i<=i##_length; ++i)
#define all(a) (a).begin(), (a).end()
#define pb push_back
inline bool isnatural(double a) { return a>=0 && ceil(a)==floor(a); }
template<typename T> inline T power(T x, T n){ return n ? power(x*x%MOD,n/2)*(n%2?x:1)%MOD : 1; }
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a; }
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b; }
template<typename T1, typename T2>inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template<typename T1, typename T2>inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
	for (int i = 0, len = v.size(); i < len; ++i){
		s << v[i]; if (i < len - 1) s << "\t";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
	for (int i = 0, len = vv.size(); i < len; ++i){
		s << vv[i] << endl;
	}
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s, const map<T1, T2>& m) {
	s << "{" << endl;
	for (typeof(m.begin()) itr = m.begin(); itr != m.end(); ++itr){
		s << "\t" << (*itr).first << " : " << (*itr).second << endl;
	}
	s << "}" << endl;
	return s;
}

/*-----8<-----8<-----*/

class Move{
public:
	ll h0,h1,w0,w1;
	Move (ll h0,ll w0,ll h1,ll w1):h0(h0),w0(w0),h1(h1),w1(w1){}
};
signed main() {
	vector<Move> ans;
	ll H,W;
	cin >> H >> W;
	vector<vector<ll>> a(H,vector<ll>(W,0));
	rep(i,H)rep(j,W)cin >> a[i][j];

	ll h,w;
	bool hold=false;

	rep(i,H){
		ll start,diff;
		if(i%2==0){
			start=0;
			diff=1;
		}else{
			start=W-1;
			diff=-1;
		}

		for(ll j=start; j<W && j>=0; j+=diff){
			if(a[i][j]%2==1){
				if(hold){
					ans.push_back(Move(h+1,w+1,i+1,j+1));
					hold=false;
				}else{
					h=i;
					w=j;
					hold=true;
				}
			}else if(hold){
				ans.push_back(Move(h+1,w+1,i+1,j+1));
				h=i;
				w=j;
			}
		}	

	}
	ll size=ans.size();
	p(size);
	rep(i,size){
		cout<<ans[i].h0<<" "<<ans[i].w0<<" "<<ans[i].h1<<" "<<ans[i].w1<<endl;
	}

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int d, g;
  cin >> d >> g;
  vector<ll> p(d), c(d);
  rep(i, d) cin >> p[i] >> c[i];

  ll ans = INF64;

  for(int bit = 0; bit < 1<<d; ++bit) {
    ll score = 0,count = 0;
    bool ok = true;
    rep(i, d) if(bit & 1<<i) {
      score += 100*(i+1)*p[i]+c[i];
      count += p[i];
    }
    for(int i = d-1; i >= 0; --i) {
      if(!(bit & 1<<i)) {
        int x = max(0, (int)ceil((double)(g-score)/(100*(i+1))));
        if(x >= p[i]) ok = false;
        else count += x;

        break;
      }
    }
    if(ok) chmin(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3608
//by Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<s32>
#define p32 pair<int,int>
#define p64 pair<ll,ll>
#define fi first
#define se second
#define ln '\n'
#define debug(x) cout << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream& operator<<(ostream& out, const pair<T,U>& p){
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename ...Args>
void print_container(const ContainerType<ValueType, Args...>& c){
	cout << "{ ";
	for(const auto& v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

int main()
{
	FASTIO;
	int n;
	cin >> n;
	v64 arr(n + 1,0);
	ll total = 0;
	for(int i = 1;i < n + 1;i++)
		cin >> arr[i],total ^= arr[i];
	if(total)
		cout << "No" << ln;
	else
		cout << "Yes" << ln;
	return 0;
}


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

int main() {
  long long x, y;
  cin >> x >> y;

  int calc = abs(y) -abs(x);

  long long res = 1LL << 60;
  if (x <= y) res = min(res, y - x);
  if (-x <= y) res = min(res, y + x + 1);
  if (x <= -y) res = min(res, -y - x + 1);
  if (-x <= -y) res = min(res, -y + x + 2);
  cout << res << endl;
}

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

int main() {
   ll n,d;
   cin>>n>>d;
   
    ll a[n][d],i,j,k;
    for(i=0;i<n;i++)
    {
        for(j=0;j<d;j++)
        cin>>a[i][j];
    }
    long double p,g;
    ll l=0,gg;
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            p=0;
            g=0;
            for(k=0;k<d;k++)
            {
                g+=pow((a[i][k]-a[j][k]),2);
            }
            // cout<<g<<endl;
            p=sqrt(g);
            gg=sqrt(g);
            if(p==gg)
            l++;
        }
    }
    cout<<l<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdio>
#include<set>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++) 
#define lint long long

struct union_find{
    vector<int> par;
    vector<int> rank;
    vector<lint> size;
    // 初期化
    union_find(int n) : par(n), rank(n), size(n){
        for(int i = 0; i < n; i++){
            par[i] = i; rank[i] = 0; size[i] = 1;
        }
    }
    // x の根を取得する
    int root (int x){
        if(par[x] == x) return x;
        par[x] = root(par[x]);
        return par[x];
    }
    // x と y の木を合併する
    lint unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return 0;
        lint ret = size[rx] * size[ry];
        if (rank[rx] < rank[ry]){
            par[rx] = ry;
            size[ry] += size[rx];
        }
        else{
            par[ry] = rx;
            size[rx] += size[ry];
            if (rank[rx] == rank[ry]) rank[rx]++;
        }
        return ret;
    }
    // x と y の木が同じなら true を返す
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(){
    lint n, m; cin >> n >> m;
    int a[m], b[m]; lint ans[m];
    rep(i, m){ cin >> a[i] >> b[i]; a[i]--; b[i]--;}
    ans[m-1] = n*(n-1)/2;
    union_find uf(n);
    rep(i, m-1){ // 0<=i<m-1
        int j = (m-2)-i; // m-2>=j>-1
        ans[j] = ans[j+1] - uf.unite(a[j+1],b[j+1]);
    }
    rep(i, m) cout << ans[i] << endl;
}


Measured memory_bytes: 4480
import collections
def BFS(graph,start,reached):
    res = 0
    next = []
    if reached[start] == 1:
        return res
    reached[start] = 1
    res += 1
    next += list(graph[start])
    while len(next):
        tmp = next.pop()
        if reached[tmp] == 1:
            continue
        res += 1
        reached[tmp] = 1
        next += list(graph[tmp])
    return res

[n,m] = [int(i) for i in input().split()]
dic = collections.defaultdict(set)
ls = [0] * n
for i in range(m):
    [a,b] = [int(j)-1 for j in input().split()]
    dic[a].add(b)
    dic[b].add(a)
ans = 0
for i in range(n):
    ans = max(ans,BFS(dic,i,ls))
print(ans)


Measured memory_bytes: 187000
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
const int MAX_N = 100100;
const int MOD = 1e9+7;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a/b; a -= t*b; swap(a, b); u -= t*v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if (e%2 == 0) { p = (p*p)%mod; e /= 2; }
            else { a = (a*p)%mod; e--; }
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

using mint = ModInt<MOD>;
mint dfs(const Graph &g, int v, int p, const int k) {
    int color = (p == -1) ? k-1 : k-2;
    if (k < g[v].size()) return 0;
    mint res = 1;
    for (auto u : g[v]) if (u != p) { res *= color; color--; } 
    for (auto u : g[v]) if (u != p)  { res *= dfs(g, u, v, k); }
    return res;
}

int main() {
    int n, k;
    cin >> n >> k;
    Graph g(n);
    for (int i = 0; i < n-1; i++) {
        int a, b; cin >> a >> b; a--; b--;
        g[a].emplace_back(b); g[b].emplace_back(a);
    }
    
    mint ans = (mint)k * dfs(g, 0, -1, k);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 66304
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch BiteEating | diff BiteEating.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address BiteEating.cpp && ./a.out

/*
 
 6/22/2019
 
 5:02-
 
 */

int N,L;

int org=0;
int f(int k) {
  int res=0;
  REP(i,N)if(i!=k) res+=L+i;
  return res;
}

void solve() {
  REP(i,N) org+=L+i;
  int res=1e7;
  REP(i,N) {
    int x=f(i);
    if(abs(res-org)>abs(x-org)) res=x;
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>L;
  solve();
  
  return 0;
}


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

int main(){

    int N, D;
    cin >> N >> D;

    vector<vector<int>> X(N, vector<int>(D));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < D; j++){
            cin >> X.at(i).at(j);
        }
    }

    int d2_tmp;
    vector<int> d2;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            d2_tmp = 0;
            for(int k = 0; k < D; k++){
                d2_tmp += pow(X.at(i).at(k) - X.at(j).at(k), 2);
            }
            d2.push_back(d2_tmp);
        }
    }

    int N_count = 0;
    int d_tmp;
    for(int i = 0; i < d2.size(); i++){
        d_tmp = sqrt(d2.at(i));
        if(pow(d_tmp, 2) == d2.at(i)){
            N_count++;
        }
    }

    cout << N_count;

    return 0;

}

Measured memory_bytes: 256
#!/usr/bin/env python3
import fractions

def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

N, M = map(int, input().split())
S = input()
T = input()
if S[0] != T[0]:
    print(-1)
    exit()

l = lcm(N, M)

Moji = {}
Moji[0] = S[0]

for i in range(1, N):
    index = i * (l//N) + 1
    Moji[index-1] = S[i]

for i in range(1, M):
    index = i * (l//M) + 1
    if index-1 in Moji and Moji[index-1] != T[i]:
        print(-1)
        exit()

print(l)


Measured memory_bytes: 17492
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef pair<ll, ll> pll;
#define all(c) begin(c), end(c)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define rep(i, n) for (ll i = 0; i < ll(n); i++)

const int N = 200005;
int dir[4]{-1, 1, 0, 0};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll h, w, k, sx, sy, gx, gy;
    cin >> h >> w >> k;
    cin >> sx >> sy >> gx >> gy;
    sx--, sy--, gx--, gy--;
    vector<string> grid(h);
    rep(i, h) cin >> grid[i];

    ll dist[h][w];
    rep(i, h) rep(j, w) dist[i][j] = 1e9;
    dist[sx][sy] = 0;
    bool vis[h][w];
    memset(vis, 0, sizeof(vis));
    queue<vl> q;
    q.push({0ll, sx, sy});
    while (!q.empty()) {
        auto state = q.front();
        q.pop();
        ll cost = state[0];
        ll cx = state[1];
        ll cy = state[2];
        rep(i, 4) {
            for (int hop = 1; hop <= k; hop++) {
                ll nx = cx + dir[i] * hop;
                ll ny = cy + dir[3 - i] * hop;
                if (nx >= h || ny >= w || nx < 0 || ny < 0 || grid[nx][ny] == '@')
                    break;
                if (dist[nx][ny] > cost + 1) {
                    dist[nx][ny] = cost + 1;
                    q.push({cost + 1, nx, ny});
                } else if (dist[nx][ny] == cost + 1)
                    continue;
                else
                    break;
            }
        }
    }
    cout << (dist[gx][gy] == 1e9 ? -1ll : dist[gx][gy]) << endl;
}

Measured memory_bytes: 19748
#include <stdio.h>
int main(){
  	int N;
    int V[N],C[N];
  	int i,sum=0;
  	scanf("%d",&N);
  	for(i=0;i<N;i++) scanf("%d",&V[i]);
  	for(i=0;i<N;i++) scanf("%d",&C[i]);  
  	for(i=0;i<N;i++){
		if(V[i]-C[i]>0) sum=sum+(V[i]-C[i]);
    }
  	printf("%d",sum);
  	return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll A, B;
    cin >> A >> B;
    rep2(i, 1, 10000) {
        ll a = 0.08 * i;
        ll b = 0.1 * i;
        if (A==a && b ==B) {
            cout << i << '\n';
            return;
        }
    }
    cout << -1 << '\n';
}

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


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

int main() {
  int a,b; cin >> a >> b;
  a &= 3;
  b %= 3;
  if(a == 0 || b == 0 || (a+b)%3 == 0){
    cout << "Possible";
  }
  else{
    cout << "Impossible";
  }
}

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

int main(){
    int a, b, c, d, e;
    cin >> a >> b >> c >> d >> e;
    if(!a)
        cout << 1 << endl;
    if (!b)
        cout << 2 << endl;
    if (!c)
        cout << 3 << endl;
    if (!d)
        cout << 4 << endl;
    if (!e)
        cout << 5 << endl;
    return 0;
}

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

int main()
{
    // 入力
    int x;
    cin >> x;
    int result;
    if (x == 1){
        result = 0;
    } else if (x == 0){
        result = 1;
    }
    cout << result << endl;
    return 0;  
}


Measured memory_bytes: 3628
#include <iostream>

using namespace std;

int main()
{
    int n, b, sol=0, c;
    cin>>n>>b;
    c = n/b;
    do
    {
      c = n/b;
      sol++;
      n = c;
    }while(n!=0);
    cout<<sol<<"\n";
    return 0;
}



Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
t = 0
ans = 0
u =[0]*n
d =[0]*n
a2 =[]
b2 =[]
c2 =[]

for i in range(n):
    a2.append([2,a[i]])
for i in range(n):
    b2.append([1,b[i]])
for i in range(n):
    c2.append([0,c[i]])
a2b2=a2+b2
b2c2=b2+c2

a2b2.sort(key = lambda x:(x[1],x[0]))
b2c2.sort(key = lambda x:(x[1],x[0]),reverse=True)

j=0
c=0
for i in range(2*n):
    if a2b2[i][0]==2:
        c+=1
    if a2b2[i][0]==1:
        u[j]=c
        j+=1
j=0
c=0
for i in range(2*n):
    if b2c2[i][0]==0:
        c+=1
    if b2c2[i][0]==1:
        d[j]=c
        j+=1
d.reverse()
for i in range(n):
    ans+=u[i]*d[i]
print(ans)


Measured memory_bytes: 67380
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second



int main() {
	ll n, a[200010], rui[200010] = { 0 }, ans = 0;
	cin >> n;
	map<ll, ll>mp;
	for (int i = 0;i < n;i++)cin >> a[i];
	for (int i = 1;i <= n;i++) {
		rui[i] = rui[i - 1] + a[i - 1];
		mp[rui[i]]++;
	}
	ans += mp[0];
	for (auto i : mp) {
		if (i.sc < 2)continue;
		ans += i.sc*(i.sc - 1) / 2;
	}
	cout << ans << endl;
	}


Measured memory_bytes: 15872
use std::io;
use std::io::prelude::*;
use std::iter::repeat;

struct SegTree {
    n: usize,
    nodes: Vec<i32>,
}

impl SegTree {
    fn init(n: usize) -> SegTree {
        let n = 1 << f64::log2(n as f64).ceil() as usize;
        SegTree {
            n,
            nodes: repeat(0).take(2 * n - 1).collect(),
        }
    }

    fn add(&mut self, s: usize, t: usize, x: i32, ni: usize, l: usize, r: usize) {
        if r <= s || t <= l {
            return;
        }
        if s <= l && r <= t {
            self.nodes[ni] += x;
            return;
        }
        let m = (l + r) / 2;
        self.add(s, t, x, 2 * ni + 1, l, m);
        self.add(s, t, x, 2 * ni + 2, m, r);
    }

    fn get(&self, i: usize, ni: usize, l: usize, r: usize) -> i32 {
        self.nodes[ni] + if self.n - 1 <= ni {
            0
        } else {
            let m = (l + r) / 2;
            if i < m {
                self.get(i, 2 * ni + 1, l, m)
            } else {
                self.get(i, 2 * ni + 2, m, r)
            }
        }
    }
}

fn main() {
    let stdin = io::stdin();
    let mut lines = stdin.lock().lines();

    let line0 = lines.next().unwrap().unwrap();
    let n = line0.split_whitespace().next().unwrap().parse().unwrap();

    let mut mst = SegTree::init(n);

    for l in lines.map(Result::unwrap) {
        let mut words = l.split_whitespace();
        let com = words.next().unwrap().parse().unwrap();
        match com {
            0 => {
                let s: usize = words.next().unwrap().parse().unwrap();
                let t: usize = words.next().unwrap().parse().unwrap();
                let x = words.next().unwrap().parse().unwrap();
                let n = mst.n;
                mst.add(s - 1, t, x, 0, 0, n);
            }
            1 => {
                let i: usize = words.next().unwrap().parse().unwrap();
                println!("{}", mst.get(i - 1, 0, 0, mst.n));
            }
            _ => (),
        }
    }
}



Measured memory_bytes: 5156