akhauriyash/Code-Regression huggingface dataset:
import math
A, B, H, M = map(int, input().split())
h = H * 30 + M * 0.5
m = M * 6
radius = abs(h-m)
ans = math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(radius)))
print(ans)

Measured memory_bytes: 9508
"use strict"
function main(arg) {
    var N = arg.trim().split("\n")[0].split(" ").map(Number)[0]
    var Ai = arg.trim().split("\n")[1].split(" ").map(Number)
    var list = {}
    for (let i = 0; i< Ai.length; i++) {
        // console.log(Ai[i] in list)
        if (!(Ai[i] in list)) {
            list[Ai[i]] = 0
        }
        list[Ai[i]] += 1
    }
    for (var i = 1; i <= N; i++) {
        i = String(i)
        if (!list[i]) {
            console.log(0)
        } else {
            console.log(list[i])
        }
    }
    // console.log(JSON.stringify(list))
}


main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 68612
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using static System.Console;
using static System.Int32;
using static System.Math;

class Program
{
    const int WARU = 1000000007;
    static void Main(string[] args)
    {
        label:
        var sp = ReadLine().Split();
        int n = Parse(sp[0]);
        long m = Parse(sp[1]);
        if (m == 1)
        {
            WriteLine(1);
        }
        else
        {
            var kusi = new bool[(int)Sqrt(m) + 2];
            int sq = (int)Sqrt(kusi.Length) + 1;
            for (int i = 2; i <= sq; ++i)
            {
                if (kusi[i]) continue;
                for (int j = 2; ; ++j)
                {
                    int index = i * j;
                    if (index < kusi.Length) kusi[index] = true;
                    else break;
                }
            }
            var sosu = new List<int>(3401);
            for (int i = 2; i < kusi.Length; ++i)
            {
                if (!kusi[i])
                {
                    sosu.Add(i);
                }
            }
            var list = new SortedList<long, int>();
            foreach (int i in sosu)
            {
                if (m % i == 0)
                {
                    list[i] = 0;
                    do
                    {
                        ++list[i];
                        m /= i;
                    } while (m % i == 0);
                    if (m < i * i)
                    {
                        break;
                    }
                }
            }
            if (1 < m)
            {
                list[m] = 1;
            }
            long result = 1;
            var array = dd(n, list.Values.Max());
            foreach(var count in list.Values)
            {
                result *= array[count - 1];
                result %= WARU;
            }
            WriteLine(result);
        }
        //WriteLine(hoge() ? "Yes" : "No");
        //goto label;
    }
    static long[] dd(int n, int count)
    {
        var result = new long[count];
        result[0] = n;
        var array = new long[n];
        for (int i = 0; i < array.Length; ++i)
        {
            array[i] = 1;
        }
        for (int i = 1; i < count; ++i)
        {
            for (int j = 1; j < array.Length; ++j)
            {
                array[j] += array[j - 1];
                if (WARU <= array[j]) array[j] -= WARU;
            }
            result[i] = array.Sum() % WARU;
        }
        return result;
    }
}


Measured memory_bytes: 14176
n, m = map(int, input().split())
rec = []
for i in range(m):
    a, b = map(int, input().split())
    rec.append((a, b))

rec = sorted(rec, key=lambda s: s[1])
pre = -1
num = 0
for x, y in rec:
    if pre == -1:
        pre = y - 1
        num += 1
    elif x <= pre:
        continue
    else:
        pre = y - 1
        num += 1

print(num)

Measured memory_bytes: 18960
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int k = sc.nextInt();
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j < m; j++) {
				if (k == i * (m - j) + j * (n - i)) {
					System.out.println("Yes");
					return;
				}
			}
		}
		System.out.println("No");
	}
}


Measured memory_bytes: 23124
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
#include<map>
#include<queue>
#include<functional>

using namespace std;
template<class T> void chmax(T& a, T b) {if(a < b){a=b;}}
template<class T> void chmin(T& a, T b) {if(a > b){a=b;}}

#define REP(i,a,n) for(int i=a;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"
#define REV(v) reverse(v.begin(),v.end())
#define SRTV(v) sort(v.begin(),v.end())
#define SRTA(a,n) sort(a,a+n)
#define MOD 1000000007

typedef long long ll;
typedef tuple<int,int,bool> Tb;

int atcoder(){
    //入力
  int x,t;
  cin >> x >> t;
    //処理
  
    //出力
    if(t<x) cout << x-t << ENT;
    else cout << 0 << ENT;
    return 0;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    --X, --Y;
    vector<int> res(N, 0);
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int d = min({abs(i-j), 
            abs(i-X)+abs(j-Y)+1, abs(i-Y)+abs(j-X)+1});
            res[d]++;
        }
    }
    for (int d = 1; d < N; ++d) cout << res[d] << endl;
}





Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		SC sc = new SC(System.in);
		int N=sc.nextInt();
		int K=sc.nextInt();
		if(N+K<0) {
			pl(-1);
		}
		else if(N+K==0){
			pl(0);
		}
		else {
			pl(1);
		}
	}
	static class SC {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;
		public SC(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
		}
		public String next() {
			if (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new UncheckedIOException(e);
			}
		}
	}
	public static void pl(Object o) {
		System.out.println(o);
	}
	public static void pl() {
		System.out.println();
	}
	public static void p(Object o) {
		System.out.print(o);
	}
	static int root(int a) {

		int ketasu=0;
		int tmp=a;
		while(tmp>0) {
			ketasu++;
			tmp/=10;
		}
		int constant=(ketasu+1)/2;	//よく使うので定数化
		if(ketasu>=1) {
			int[] suuji=new int[constant];
			tmp=a;
			for(int i=0; i<constant; i++) {
				suuji[constant-1-i]=a%100;
				a/=100;
			}
			int ans=0;
			int kai=0;
			int mae=0;
			if(constant<=1) {
				for(int i=10; i>=0; i--) {
					if(suuji[0]>=i*i) {
						return i;
					}
				}
			}
			else {
				for(int i=0; i<constant; i++) {
					mae+=kai*2;
					for(int j=9; j>=0; j--) {
						if((mae*10+j)*j<=suuji[i]) {
							ans=ans*10+j;
							mae*=10;
							kai=j;
							if(i+1<constant) {
								suuji[i+1]+=(suuji[i]-(mae+j)*j)*100;
							}
							break;
						}
					}
				}
			}
			return ans;
		}
		else {
			return 0;
		}
	}
}


Measured memory_bytes: 24456
#include <iostream>

using namespace std;

int main() {
	int N;
	int v[200];
        int dpA[1000000], dpB[1000000];
	for (int i = 0; i<=200; i++) v[i] = i * (i + 1)*(i + 2) / 6;
	dpA[0] = dpB[0] = 0;
	for (int i = 1; i<1000000; i++) {
		dpA[i] = dpB[i] = i;
		for (int j = 0; i - v[j] >= 0; j++) {
			dpA[i] = min(dpA[i], dpA[i - v[j]] + 1);
			if (v[j] % 2 == 1)
				dpB[i] = min(dpB[i], dpB[i - v[j]] + 1);
		}
	}
	while (cin >> N, N)
		cout << dpA[N] << " " << dpB[N] << endl;
}


Measured memory_bytes: 10920
#include<iostream>
#include <iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <numeric>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main()
{
  string s;
  cin >> s;
  int q;
  cin >> q;
  vector<int> t(q);
  vector<int> f(q);
  vector<char> c(q);
  for(int i = 0;i < q;i++)
  {
    cin >> t[i];
    if(t[i] == 2)
    {
      cin >> f[i] >> c[i];
    }
  }
  int top = 0;
  for(int i = 0;i < q;i++)
  {
    if ( t[i] == 1 )
    {
      top = !top;
    }
    else 
    {
      if (top)
      {
        if ( f[i] == 1 )
        {
          s.insert(s.end(), c[i]);
        }
        else
        {
          s.insert(s.begin(), c[i]);
        }
      }
      else
      {
        if ( f[i] == 1 )
        {
          s.insert(s.begin(), c[i]);
        }
        else
        {
          s.insert(s.end(), c[i]);
        }
      }
    }
  }
  if (top)
  {
    reverse(s.begin(),s.end());
  }
  for(int i = 0;i < s.size();i++)
  {
    cout << s[i];
  }
  cout << endl;
}


Measured memory_bytes: 2820
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T chmin(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T chmax(T& l, T r) {
    return l = max(l, r);
}
// ============ template finished ============

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

    vector<ll>A(N);
    rep(i, N) {
        ll tmp;
        cin >> tmp;
        A[i] = tmp - 1;
    }

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

    set<ll> went = { 0,A[0] };
    deque<ll> route = { 0,A[0] };
    while (true) {
        ll next = A[route.back()];
        route.push_back(next);
        if (went.find(next) != went.end())break;
        else went.insert(next);
    }

    while (route.front() != route.back() && K > 0) {
        route.pop_front();
        K--;
    }
    if (K == 0) {
        cout << route.front() + 1 << endl;
        return 0;
    }

    ll loopSize = route.size() - 1;
    K %= loopSize;
    cout << route[K] + 1 << endl;
    return 0;
}


Measured memory_bytes: 15444
N,M=map(int,input().split())
stu=[list(map(int,input().split())) for _ in range(N)]
che=[list(map(int,input().split())) for _ in range(M)]

for i in range(N):
    dis=[]
    for k in range(M):
        dis.append(abs(stu[i][0]-che[k][0])+abs(stu[i][1]-che[k][1]))
    shortest=min(dis)
    print(dis.index(shortest)+1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
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 (b<a) { a=b; return 1; } return 0; }

using ll = long long;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int INF = 1<<30;
const ll mod = 1000000007LL;

int main() {
  ll N;
  cin>>N;
  bool ok = false;
  for(ll h = 1; h <=3500;h++){
    for(ll n = 1; n <= 3500; n++){
      if(4LL*h*n-N*n-h*N>0&&N*h*n%(4LL*h*n-N*n-h*N)==0){
        cout<<h<<" "<<n<<" "<<N*h*n/(4LL*h*n-N*n-h*N)<<endl;
        ok=true;
        break;
      }
    }
    if(ok) break;
  }
}

Measured memory_bytes: 256
n, q = [int(_) for _ in input().split()]
s = [_ for _ in input()]

lr = []
for i in range(q):
    lr.append([int(_) for _ in input().split()])
number_ac = [0]
state = 0
for i in range(1, len(s)):
    if (s[i - 1] == "A" and s[i] == "C"):
        state += 1
    number_ac.append(state)

def ans(l, r):
    if l == 0:
        res = number_ac[r]
    else:
        res = number_ac[r] - number_ac[l - 1]
        if (s[l-1] == "A" and s[l] == "C"):
            res -= 1
    return res

for i in range(q):
    print(ans(lr[i][0] - 1, lr[i][1] - 1))

Measured memory_bytes: 25096
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		auto ws = vector<string> {
			"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT",
		};
		ll ans = 0;
		REP(i, ws.size()) {
			if(ws[i]==s) ans = 7-i;
		}
		
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
 
int main()
 {
  int a,b,c,sum=0 ;
  char s[911];
  scanf("%s",s) ;
  if((s[2]==s[3])&&(s[4]==s[5]))
  {
      printf("Yes") ;
  }
  else
  {
      printf("No") ;
  }
  return 0 ;
 }

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

int main(){
    long N, M;
    cin >> N >> M;
    if(N == 1 && M == 1){
        cout << 1 << endl;
    }else if(N == 1){
        cout << M - 2 << endl;
    }else if(M == 1){
        cout << N - 2 << endl;
    }else{
        cout << (N - 2) * (M - 2) << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define to edge[i].v
#define mp make_pair
#define rint register int
#define debug(x) cerr<<#x<<"="<<x<<endl
#define fgx cerr<<"-------------"<<endl
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
int vis[100],N,M,a[100],b[100];
vector<ll> v[100];
void dfs(int x,int k,ll c=0)
{	if(x==0){if(N==M)v[k].push_back(c);return;}
	int tag=1,la; dfs(x-1,k,c);
	for(rint i=2;x*i<=50;i++) if(vis[x*i]){tag=0;break;}
	if(tag&&N>=x&&N%x>=M) la=N,N%=x,vis[x]=1,dfs(x-1,k,c+(1LL<<x)),vis[x]=0,N=la;
}
int main()
{	int n; ll cur=(1LL<<51)-2; cin>>n;
	for(rint i=1;i<=n;i++) scanf("%d",&a[i]);
	for(rint i=1;i<=n;i++) scanf("%d",&b[i]);
	for(rint i=1;i<=n;i++) N=a[i],M=b[i],dfs(50,i);
	for(rint i=1;i<=n;i++) if(!v[i].size()) return !printf("-1");
	for(rint i=50;i>=1;i--)
	{	cur^=(1LL<<i); int ok=1;
		for(rint j=1;j<=n;j++)
		{	int tag=0;
			for(rint k=0;k<v[j].size();k++) if((v[j][k]|cur)==cur){tag=1;break;}
			if(!tag){ok=0;break;}
		}
		if(!ok) cur^=(1LL<<i);
	}
	cout<<cur;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

string print_ll(LL v) {
  string s = "";
  while(v != 0) {
    s = (v % 2 == 0 ? '0' : '1') + s;
    v >>= 1;
  }
  return s;
}

int main() {
  LL N, K;
  cin >> N >> K;
  vector<LL> A(N), B(N);
  REP(i, N) { cin >> A[i] >> B[i]; }
  LL ret = 0;
  REP(i, 32) {
    if(i == 0 || K & (1 << i)) {
      LL tret = 0;
      LL nK = ((K >> i) << i) - (i == 0 ? 0 : 1);
      cerr << print_ll(nK) << endl;
      REP(i, N) {
        if((nK | A[i]) == nK) {
          tret += B[i];
        }
      }
      ret = max(ret, tret);
    }
  }
  cout << ret << endl;
}

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

bool f(int x) {
  int keta = 0;
  while (x) {
    keta++;
    x /= 10;
  }
  return keta%2 == 1;
}

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (f(i)) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

int ketasuu(int x){
  for(int i=0;i<11;i++){
    if(x/(int(pow(10,10-i)))!=0){
      return 11-i;
    }
  }
}

int main() {
  int64_t N;
  cin >> N;
  int i=sqrt(N);
  int answer;
  while(i!=0){
    if(N%i==0){
      cout << ketasuu(N/i) << endl;
      return 0;
    }
    i--;
  }
}

Measured memory_bytes: 256
N=int(input())
h=list(map(int,input().split()))

a=[0]*N
a[1] = abs(h[0]-h[1])

for i in range(2,N):
    a[i]=min(a[i-2]+abs(h[i-2]-h[i]),a[i-1]+abs(h[i-1]-h[i]))

print(a[N-1])


        

Measured memory_bytes: 13980
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

const int N = 2e5 + 10;
int n , K , L , posa[N] , posb[N];
int fa[N];
int F(int x) {return fa[x]==x?x:fa[x]=F(fa[x]);}

void connect(int m,int *pos) {
  rep(i,1,n+1) fa[i]=i;
  rep(i,0,m) {
    int u,v;scanf("%d%d",&u,&v);
    fa[F(v)]=F(u);
  }
  rep(i,1,n+1) pos[i]=F(i);
}

int main(){
  scanf("%d%d%d",&n,&K,&L);
  connect(K , posa);
  connect(L , posb);
  map<pii,int> cnt;
  rep(i,1,n+1) cnt[mp(posa[i],posb[i])]++;
  rep(i,1,n+1) printf("%d%c",cnt[mp(posa[i],posb[i])]," \n"[i==n]);
  return 0;
}


Measured memory_bytes: 14336
#include<iostream>
#include<cstdint>
using namespace std; // 575

const int MAX = 100000;
const int INF = 1073741823; // 10^30-1、使わない辺とかに用いる
int main() {
	int N;
	static int A[MAX], mi = INF, neg = 0, zero = 0;
	int64_t sum = 0;
	cin >> N;
	for (int i = 0;i < N;++ i) {
		cin >> A[i];
		if (A[i] < 0) ++ neg;
		mi = min(mi, abs(A[i]));
		sum += abs(A[i]);
	}
	
	if (neg & 1) sum -= mi << 1;
	cout << sum;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

操作によって負数の位置は移動させることができ、偶数個は消すことができる
よって負数が奇数個のとき、最小要素に負を押し付けて終わり！
*/

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

int main(){
  int N;
  int a;
  cin >> N;
  
  for(int i=1;i<=9;i++){
    if(N%i ==0){//iで割り切れる
      a =i;
      if((1<=N / a)&&(N/a <=9)){
        cout << "Yes" << endl;
        break;
      }
    }
    if((i==9)&&(N%i !=0)) cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}
const int INF = 1e18;

signed main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;

    vi cu(N), du(N), cd(N), dd(N);
    cu[0] = du[0] = cd[0] = dd[0] = A;

    rep(i, N) {
        int r = N-1-i;
        int hh, hl, lh, ll;
        hh = du[i] - r*C;
        hl = cu[i] - r*D;
        lh = cd[i] + r*D;
        ll = dd[i] + r*C;

        if(B<=hh && B>=hl) {
            cout << "YES" << endl;
            return 0;
        }
        if(B<=lh && B>=ll) {
            cout << "YES" << endl;
            return 0;
        }

        cu[i+1] = cu[i]+C;
        du[i+1] = du[i]+D;
        cd[i+1] = cd[i]-C;
        dd[i+1] = dd[i]-D;
    }

    cout << "NO" << endl;

    return 0;
}

Measured memory_bytes: 15872
import java.util.*;
	
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int h = sc.nextInt(), w = sc.nextInt();
		int n = sc.nextInt();
		int a[] = new int[n+1];
		
		int g[][] = new int[h][w];
		
		for(int i= 1;i<=n;i++){
			a[i] = sc.nextInt();
		}
		
		int p=1;
		int r = 0, c = 0;
		int dir = 1;
		while(p<=n){
			while(p<=n && c<w){
				g[r][c] = p;
				c++;
				a[p]--;
				if(a[p]==0)
					p++;
			}
			r++;
			c--;
			while(p<=n && c>=0){
				g[r][c] = p;
				c--;
				a[p]--;
				if(a[p]==0)
					p++;
			}
			r++;
			c++;
		}
		
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				System.out.print(g[i][j]+" ");
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 33128
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string s,ss;
   cin>>ss;

    if(ss.size()<=7)
    {
        if(ss=="keyence") cout<<"YES\n";
        else cout<<"NO";
        return 0;
    }
   for(int i=0;i<ss.size();i++)
   {
       s=ss;
       s.erase(i,s.size()-7);

       if(s=="keyence")
       {
           cout<<"YES\n";
            return 0;
       }
   }

   cout<<"NO\n";
   return 0;

}


Measured memory_bytes: 256
n = input()
code = raw_input().split()
# DP(N, <parentheses nested>)
dp = [[0]*3 for i in xrange(n)]
dp[0] = [int(code[0]), -10**18, -10**18]
for i in xrange(1,n):
    op, a = code[2*i-1: 2*i+1]
    v = int(a)
    if op is "+":
        dp[i][0] = max(dp[i-1][0]+v, dp[i-1][1]-v, dp[i-1][2]+v)
        dp[i][1] = max(              dp[i-1][1]-v, dp[i-1][2]+v)
        dp[i][2] =                                 dp[i-1][2]+v
    else:
        dp[i][0] = max(dp[i-1][0]-v, dp[i-1][1]+v, dp[i-1][2]-v)
        dp[i][1] = max(dp[i-1][0]-v, dp[i-1][1]+v, dp[i-1][2]-v)
        dp[i][2] = max(              dp[i-1][1]+v, dp[i-1][2]-v)
print max(dp[-1])

Measured memory_bytes: 27140
#include <iostream>
#include <vector>
#include <algorithm>

using MyPair = std::pair<int, long long>;

int main()
{
	long long N, A, B, C, D, E;
	std::cin >> N >> A >> B >> C >> D >> E;

	// 経過時間
	long long totalTime = 0;

	// ボトルネックになってる箇所を調べるために、昇順ソートする
	std::vector<MyPair> v = { {0, A}, {1, B}, {2, C}, {3, D}, {4, E} };
	std::sort( v.begin(), v.end(), []( MyPair a, MyPair b ) {
			return ( a.second  < b.second );
			} );

	// ボトルネック箇所なので、最低必要な時間がこれ
	totalTime = N / v[0].second + ( N % v[0].second != 0 );

	// ボトルネックの箇所までかかる時間を足す
	totalTime += v[0].first; // 都市Nまでの移動時間をそのまま足せばOK

	// ボトルネックの箇所以降の時間を足す
	totalTime += ( 4 - v[0].first );

	std::cout << totalTime << std::endl;

	return ( 0 );
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;
int main(){
    string s,t,n;
    cin >> s >> t;
    if(s.size()+1==t.size()&&t.substr(0,s.size())==s){
        cout << "Yes" << endl;
    }else{
        cout << "No" <<endl;
    }
    
  return 0;
}

Measured memory_bytes: 3628
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        // System.out.println(line);
        String[] lst = line.split(" ");

        int five_cnt = 0;
        int seven_cnt = 0;

        for(int i = 0; i < lst.length; i++){
            int cnt = Integer.parseInt(lst[i]);
            if(cnt == 5){
                five_cnt += 1;
            }
            else if(cnt == 7){
                seven_cnt += 1;
            }
        }
        if(five_cnt == 2 && seven_cnt == 1){
            System.out.println("YES");
        }
        else{
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 20692
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		long K = Long.parseLong(in.readLine());
		long result = K / 500 * 1000;
		K = K % 500;
		result += K /  5 * 5;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

}


Measured memory_bytes: 21204
# Input
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from collections import Counter

n,m = li()
a = list(li())

acum = [0]

for ai in a:
    acum.append((acum[-1] + ai) % m)

cnts = Counter(acum)
ans = 0
for key, val in cnts.items():
    ans += (val-1)*val // 2

print(ans)




Measured memory_bytes: 17412
s = gets.chomp

q = gets.chomp.to_i

chars = []
s.each_char do |c|
  chars << c
end

direction = true
q.times do |i|
  arr = gets.chomp.split(" ")
  if arr[0].to_i == 1
    direction = !direction
    next
  end

  if (arr[1].to_i == 1 && direction) || (arr[1].to_i != 1 && !direction)
    chars.unshift(arr[2])
  else
    chars.push(arr[2])
  end
end

s = chars.join("")
s.reverse! unless direction

puts s

Measured memory_bytes: 28924
#include <bits/stdc++.h>
using namespace std;
int mochi[101];
int main()
{
	int ans,i,n;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&mochi[i]);
	}
	sort(mochi+0,mochi+n);
	ans=unique(mochi,mochi+n)-mochi;
	printf("%d",ans);
	return 0;
}

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

int main(){
  int64_t N,cnt=0,a;
  cin >> N;
  if(N%2==1){
    cout << 0 << endl;
  }else{
    N=N/10;
    cnt+=N;
    for(int64_t i=0;i<100000;i++){
      a=1;
      for(int j=0;j<i+1;j++){
        a*=5;
      }
      if(N/a>=1){
        cnt+=N/a;
      }else{
        break;
      }
    }
    cout << cnt << endl;
  }
}


Measured memory_bytes: 256
//:Ditttoo
#include<bits/stdc++.h>
#define int long long int 
using namespace std;
int32_t main()
{
	string s,t;
	cin>>s>>t;
	int n= s.size() , m= t.size();

	int dp[n+1][m+1];
	memset(dp,0,sizeof(dp));

	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
		{
			if(s[i]==t[j]){
				dp[i+1][j+1] = 1 + dp[i][j];
			}
			else 
				dp[i+1][j+1] = max(dp[i][j+1] , dp[i+1][j]);
		}
	}

	

	// cout<<dp[n][m];
	string a;
    
	for(int i=n , j=m ; i> 0 & j>0 ;){
		if(s[i-1] == t[j-1]){
			a += s[i-1];
			i--;j--;
		}

		else if(dp[i-1][j] > dp[i][j-1])i--;
		else j--;
	 }
	// for(int i=0;i<=n;i++){
	// 	for(int j=0;j<=m;j++){
	// 		cout<<dp[i][j]<<" "; 
	// 	}cout<<"\n";
	// }??
	 reverse(a.begin(),a.end());
	cout << a;
	return 0;
}        

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

int main() {
	ios_base::sync_with_stdio( false );

	char a, b;
	cin >> a >> b;

	if( a == 'H' ) {
		cout << b << endl;
	}
	else {
		cout << (b == 'H' ? 'D' : 'H') << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define all(x) (x).begin() , (x).end()
#define f first
#define s second
#define pr(x) cout<<x<<endl;
#define pr2(x,y) cout<<x<<" "<<y<<endl;
#define pr3(x,y,z) cout<<x<<" "<<y<<endl;
#define prv(v) for(auto x:v) cout<<x<<" ";
#define ffs fflush(stdout);
#define int ll
using namespace std;
 
const ll MOD = 1e9+7;
const ll INF = 1e12;
const ll LOG = 29;
#define PI 3.141592653589793238 


long long binpow(long long a, long long b) {
    a%=MOD;    
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res * a)%MOD;
        a = (a * a)%MOD;
 
        
        b >>= 1;
    }
    res%=MOD;
    return res;
}
const ll N =(2e5+5);
ll nxt[N];
ll a[N];
void solve(){
	ll n,k;
	cin>>n;
	cin>>k;
	
	for(int i =1;i<=n;i++){
		cin>>a[i];
		nxt[i]=a[i];
	}
	ll sz = 0;
	ll cur = 1;
	set<ll> se;
	vll gg;
	ll pos = -1;
	while(true){
		if(se.find(cur) != se.end()) {pos = cur;break;}
		sz++;
		se.insert(cur);
		gg.pb(cur); 
		cur = nxt[cur];
	}
	assert(pos != -1);
	vll gg2;
	se.clear();
	while(true){
		if(se.find(pos) != se.end()) break;
		gg2.pb(pos);
		se.insert(pos);
		pos=nxt[pos];
	}
	ll sz2 = 1ll*gg2.size();
	
	ll pehle = sz-sz2;
	if(k <= pehle){
		cout<<gg[k]<<endl;
		return;
	}
	k-=pehle;
	
	k%=sz2;
	cout<<gg2[k]<<endl;
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     
    ll t=1;
 //   cin>>t;
    while(t--){
        solve();
    }    
}

Measured memory_bytes: 19392
import sys
input = sys.stdin.readline

n = int(input())
A = list(map(int, input().split()))
B = [0 for _ in range(len(A))]
k = 10000


def main():
    CountingSort(A, B, k)
    print(' '.join(map(str, B)))


def CountingSort(A, B, k):
    C = [0 for _ in range(k)]

    # Aの要素iの出現回数をCiに書きこむ
    for i in range(n):
        C[A[i]] += 1

    # 累積和を求める
    for i in range(k):
        if i > 0:
            C[i] = C[i] + C[i - 1]

    for j in range(len(B) - 1, -1, -1):
        B[C[A[j]] - 1] = A[j]
        C[A[j]] -= 1


if __name__ == '__main__':
    main()



Measured memory_bytes: 241932
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
#define range(i, a, b) for (int i = a; i < b; ++i)
#define rep(i, n) range(i, 0, n)
const ll INF = 1e10;
#define pb push_back
const double eps = 1e-10;

int main()
{
    int n;
    cin >> n;
    rep(i, n)
    {
        vector<double> x(4), y(4);
        rep(j, 4) cin >> x[j] >> y[j];
        double a = (x[3] - x[2]) * (y[1] - y[0]) - (x[1] - x[0]) * (y[3] - y[2]);
        if (abs(a) > eps) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
        }
    }
}



Measured memory_bytes: 3196
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };

    ($iter:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

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

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
// r#"2018 218"# => "Yes",
// r#"2763 0"# => "No",
r#"999"# => "ABC",

}

fn solve(src: &str) -> String {
    input! {
        source = src,
        a: usize,
        b: usize,
    }

    if a <= 8 && b <= 8 {
        "Yay!"
    } else {
        ":("
    }.to_string()
}

Measured memory_bytes: 4352
#define _USE_MATH_DEFINES
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<string>
#include<cctype>
#include<iomanip>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

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

	int n;//学生の数
	double sum = 0.0;
	double variance_sum = 0.0;
	double m;//平均点
	double a;//分散

	cin >> n;

	while (n != 0){
		//要素数nのvector作成
		vector<double> s(n);
		
		//sに得点を入れていく&合計を計算
		rep(i, n){
			cin >> s[i];
			sum += s[i];
		}

		m = sum / n;
		rep(i, n){
			variance_sum += (s[i] - m) * (s[i] - m);
		}
		a = sqrt(variance_sum / n);

		cout << fixed;
		cout << setprecision(5) << a << '\n';

		variance_sum = 0.0;
		sum = 0.0;
		cin >> n;
	}

	return 0;
}


Measured memory_bytes: 3320
N, M, C = map(int, input().split())
B = list(map(int, input().split()))

ans = 0

for i in range(N):
  A = list(map(int, input().split()))
  work = C
  for j in range(M):
    work += A[j] * B[j]
  if work > 0:
    ans += 1
    
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define all(v) v.begin(), v.end()
#define mem(arr) memset(arr, 0, sizeof(arr))
#define ff first
#define ss second
#define int long long int
const int MOD = 1e9 + 7;
const int INF = 1e18;
const int N = 1e6 + 1;
vector<int> g[N];
vector<int> vis(N);
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc = 1;
    while(tc--){
        double a, b, c;
        cin >> a >> b >> c;
        double val = a / c;
        cout << (val <= b ? "Yes\n" : "No\n");
    }
}

Measured memory_bytes: 34632
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>

using namespace std;



int gcd( int a , int b){

    int r, tmp;

    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }

    /* ユークリッドの互除法 */
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int test(vector<int> S){

    int sum = 0;
    for (int i : S) sum += i;

    for(int a : S){
        if( gcd(a , sum - a) == 1){
            cout << "no.." << endl;
            return -1;
        }
    }

    cout << "ok!" << endl;
    return 0;
}

int main() {

    int N;
    cin >> N;

    vector<int> psh;
    for(int pi = 2 ; pi < 30000 ; pi++){
        if(pi%2 == 0 || pi%5==0 || pi%3==0) {
            if(pi == 5) continue;
            psh.push_back(pi);
        }
    }

    vector<int> S;
    S.push_back(5);
    int ai = 0;

    while(true) {
        if(S.size() >= N-2) break;
        S.push_back(psh[ai]);
        ai++;
    }


    int sum = 0;
    for (int i : S) sum += i;
    while(true) {
        if( (sum + psh[ai])%3 == 0){
            S.push_back(psh[ai]);
            sum += psh[ai];
            break;
        }
        ai ++;
    }


    for(int thr = (psh[ai]/3+1)*3 ; thr < 30000 ; thr +=3 ){
        if((sum + thr)%10 == 0) {
            S.push_back(thr);
            break;
        }
    }


    for (int i : S) cout << i << " ";
    cout << endl;

    // test(S);

}

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

int main(){
  char c;
  char b='0';
  int s=0;
  while(true){
    scanf("%c", &c);
    if(c=='0' && b=='\n')break;
    if(c=='\n'){
      cout << s << endl;
      s=0;
    } else {
      s+=int(c-'0');
    }
    b=c;
  }
}


Measured memory_bytes: 3164
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,b,sum=0;
    cin>>n>>b;
    int a[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    for(int i=0;i<b;i++)
        sum+=a[i];
    cout<<sum<<endl;

}


Measured memory_bytes: 3548
#include <iostream>
#include <queue>
#include <map>
#include <list>
#include <vector>
#include <string>
#include <stack>
#include <limits>
#include <climits>
#include <cassert>
#include <fstream>
#include <cstring>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <ciso646>
#include <set>
#include <array>
#include <unordered_map>

using namespace std;

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

#define inf 0x3f3f3f3f
#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define SET(a,c) memset(a,c,sizeof a)
#define CLR(a) memset(a,0,sizeof a)
#define VS vector<string>
#define VI vector<ll>
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define MIN(a,b) (a>b?b:a)
#define MAX(a,b) (a>b?a:b)
#define pi 2*acos(0.0)
#define INFILE() freopen("in0.txt","r",stdin)
#define OUTFILE()freopen("out0.txt","w",stdout)
#define ll long long
#define ull unsigned long long
#define pii pair<ll,ll>
#define pcc pair<char,char>
#define pic pair<ll,char>
#define pci pair<char,ll>
#define eps 1e-14
#define FST first
#define SEC second
#define SETUP cin.tie(0), ios::sync_with_stdio(false), cout << setprecision(15)

namespace {
	struct input_returnner {
		ll N; input_returnner(ll N_ = 0) :N(N_) {}
		template<typename T> operator vector<T>() const { vector<T> res(N); for (auto &a : res) cin >> a; return std::move(res); }
		template<typename T> operator T() const { T res; cin >> res; return res; }
		template<typename T> T operator - (T right) { return T(input_returnner()) - right; }
		template<typename T> T operator + (T right) { return T(input_returnner()) + right; }
		template<typename T> T operator * (T right) { return T(input_returnner()) * right; }
		template<typename T> T operator / (T right) { return T(input_returnner()) / right; }
		template<typename T> T operator << (T right) { return T(input_returnner()) << right; }
		template<typename T> T operator >> (T right) { return T(input_returnner()) >> right; }
	};
	template<typename T> input_returnner in() { return in<T>(); }
	input_returnner in() { return input_returnner(); }
	input_returnner in(ll N) { return std::move(input_returnner(N)); }
}

ll MOD = 1e9 + 7;

void solve();

signed main() {
	SETUP;
	solve();
#ifdef _DEBUG
	system("pause");
#endif
	return 0;
}

#define int ll

int f(vector<int> x) {
	vector<int> dp(x.size()-1);
	dp[0] = x[1] - x[0];
	int sum = dp[0];
	FOR(i, 1, dp.size()) {
		dp[i] = dp[i - 1] + ((i + 1) * (x[i + 1] - x[i]))%MOD;
		dp[i] %= MOD;
		sum = (sum + dp[i]) % MOD;
	}
	return sum;
}

void solve() {
	int N, M; cin >> N >> M;
	vector<int> x(N), y(M);
	for (auto &a : x) cin >> a;
	for (auto &a : y)cin >> a;
	cout << (f(x) * f(y)) % MOD << endl;
}


Measured memory_bytes: 4208
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define reps(i,n) for(int i=1;i<(int)(n);i++)

typedef long long ll;
using namespace std;
int main()
{
  string n;
  cin>>n;
  ll sum=0;
  rep(i,n.length()){
    sum+=n[i]-'0';
  }

  if(sum%9==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 3720
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  string s;
  cin >> s;
  int a = 0, b = 0;
  for (char x : s) {
    if (x == '0') {
      a++;
    } else {
      b++;
    }
  }
  cout << 2*min(a, b) << endl;
  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
constexpr long double EPS = 1e-15;
const long double PI = acos(-1);
constexpr int inf = 2e9;
constexpr ll INF = 2e18;
constexpr ll MOD = 1e9+7;
constexpr ll MOD1 = 998244353;
typedef pair<ll,ll> P;
//#define all(v) (v).begin(), (v).end()
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second
//#define mp make_pair

void solve() {
    string a,b;
    cin >> a >> b;
    int ans = 0;
    REP(i,3) {
        ans += a[i] == b[i];
    }
    cout << ans << endl;
}

int main(int argc, char *argv[]){
    // /* Regular */
    // int case_num = 1;
    // if (argc > 1 && stoi(argv[1])) cin >> case_num;
    // REP(case_no, case_num) {
    //   cerr << endl << "case " << case_no + 1 << endl;
    //   solve();
    // }
    /* AOJ */
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,s,a[1000005],p[1000005];
inline long long read()							
{

    char ch;
    while((ch=getchar())<'0'||ch>'9'){;}
    long long res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
    res=res*10+ch-'0';
    return res;
}
int main()
{
    n=read(),s=read();
    for(long long i=1;i<=n;i++)
    {
    	a[i]=read(),p[i]=read();
    }
    long long l=1,r=n;
    long long ans=0;
    while(l<=r)
    {
    	if(a[l]>=s)
     	{
    		ans+=a[r]-s;
    		break;
    	}
    	if(a[r]<=s)
    	{
     		ans+=s-a[l];
    		break;
    	}
    	ans+=a[r]-a[l];
    	if(p[l]>=p[r])
    	{
    		while(p[l]>=p[r]&&l<r)
    		{
    			p[l]+=p[r];
    			r=r-1;
    		}	
    	}
    	else 
    	{
    		while(p[r]>p[l]&&l<r)
    		{
    			p[r]+=p[l];
    			l+=1;
    		}
    	}
    }
	cout<<ans<<endl;
	return 0;
} 

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
using vec_int = vector<int>;
using P = pair<int,int>;
using T = tuple<int,int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main(){
    string S, T;
    cin>>S;
    cin>>T;
    int flag=1;
    if(S.size()==T.size()-1){
        rep(i,S.size()){
            if(S.at(i)==T.at(i)){
                continue;
            }else{
                flag=0;
            }
        }
    }else{
        flag=0;
    }

    if(flag==0){
        cout<<"No"<<endl;
    }else{
        cout<<"Yes"<<endl;
    }

}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
int main(){
	long long N,K;
	scanf("%lld %lld",&N,&K);
	
	vector< pair<int,int> > S;
	
	REP(i,N){
		int a,b;
		SCD2(a,b);
		pair<int,int> x = make_pair(a,b);
		S.push_back(x);
	}
	
	sort(S.begin(),S.end());
	
	int i = 0;
	while(true){
		int a = S[i].first;
		int b = S[i].second;
		
		K = K - b;

		if (K <= 0){
			PRINTD(a);
			return 0;
		}
		
		
		i++;
	}
	
	
	return 0;
}








Measured memory_bytes: 1400
Main(myin());
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim();}
function myout(t){console.log(t);}//standard output
function myerr(t){console.error(t);}//standard error
//[no]param
//不明値:何もしない  1:数値へ変換  2:半角SPで分割  3:改行で分割  4:半角SPで分割し、数値配列へ
//5:改行で分割し、数値配列へ  6:1文字に分割  7:1文字に分割し、数値配列へ
//8:半角SPで結合　9:改行で結合　0:文字なしで結合
function myconv(i,no){switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 3:return i.split("\n");case 4:return i.split(" ").map((a)=>Number(a));case 5:return i.split("\n").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}
function Main(input) {
  input = myconv(input,3);
  var N = myconv(input[0],1);
  input.shift();
  var X = input[N];
  var output = 0;
  var flag = false;
  for(var i = 0; i< N; i++){
    var kyoku = myconv(input[i],2)[0];
    var t = myconv(input[i],4)[1];
    if(kyoku == X){
       flag = true;
      continue;
    }
    if(flag){
       output += t;
    }
  }
  myout(output);
}

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

int main(){
    int N;
    cin >> N;
    vector<string> S(N);
    for (int i=0; i<S.size(); i++) cin >> S.at(i);

    sort(S.begin(), S.end());

    int ans = N;

    for (int i=1; i<S.size(); i++){
        if (S.at(i) == S.at(i-1))
            ans -= 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 9528
h, w = map(int, input().split())
cambus = [list(input()) for _ in range(h)]
for i in range(h):
    for j in range(w):
        if cambus[i][j] == '#':
            if i-1 >= 0 and cambus[i-1][j] == '#':
                continue
            elif j-1 >= 0 and cambus[i][j-1] == '#':
                continue
            elif i+1 <= h-1 and cambus[i+1][j] == '#':
                continue
            elif j+1 <= w-1 and cambus[i][j+1] == '#':
                continue
            else:
                print('No')
                exit()
print('Yes')

Measured memory_bytes: 9132