akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long int           i64;
typedef pair<int, int>          pii;
typedef vector<int>             vi;
typedef vector<double>          vd;
typedef vector<string>          vs;
typedef vector<pair<int, int> > vii;
#define all(c)				c.begin(), c.end()
#define clr(x,y)			memset(x,y,sizeof x)
#define MOD                 1000000007
#define eps                 1e-9
#define INF                 0x3f3f3f3f3f3f3f3f // 4,557,430,888,798,830,399
#define inf                 0x3f3f3f3f // 1,061,109,567
#define PI                  acos(-1.0)  // 3.1415926535897932
#define max3(x, y, z)       max(max(x, y), z)
#define min3(x, y, z)       min(min(x, y), z)
#define to_lower(x)         transform(x.begin(), x.end(), x.begin(), ::tolower)
#define to_upper(x)         transform(x.begin(), x.end(), x.begin(), ::toupper)
#define vin(x)              for(auto &m : x) cin >> m;
#define f                   first                
#define s                   second 
#define lcm(x, y)           (x * y) / __gcd(x, y)       

int dr[] = {-1, 0, 1,  0};
int dc[] = { 0, 1, 0, -1};
int dx[] = {+0,+0,+1,-1,-1,+1,-1,+1};
int dy[] = {-1,+1,+0,+0,+1,+1,-1,-1};
int hr[] = {1, 1, 2, 2,-1,-1,-2,-2};
int hc[] = {2,-2, 1,-1, 2,-2, 1,-1};

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

template<typename T>T power(T n, T p){ T res = 1;while(p > 0){if(p & 1)res *= n;n *= n;p >>= 1;}return res;}
template<typename T>T bigmod(T n, T p, T m){n %= m;T res = 1;while(p > 0){if(p & 1)res = res * n % m;n = n * n % m;p >>= 1;}return res;}

int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout << fixed;
    cout << setprecision(6);
    #ifndef ONLINE_JUDGE
        clock_t tStart = clock();
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    int D, T, S;
    cin >> D >> T >> S;
    cout << (D <= T * S ? "Yes" : "No");
    #ifndef ONLINE_JUDGE
        fprintf(stderr, "\n>> Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
	return 0;
}


Measured memory_bytes: 3644
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end
N, M = gets_i_list

l_list, r_list = [], []
M.times do |i|
   l_list[i], r_list[i] = gets_i_list
end

ans = if r_list.min - l_list.max >= 0
  r_list.min - l_list.max + 1
else
  0
end

puts ans


Measured memory_bytes: 4080
import sys
sys.setrecursionlimit(10**7)
N, M =map(int, input().split())
G=[[]for i in range(N+1)]
for i in range(M):
    a, b, c = map(int,input().split())
    G[a] += (b,c),
    G[b] += (a,-c),

d = [10**9]*(N+1)
flag = True
def f(v, u):
    global flag
    if not flag:
        d[v] = 0
        return 0
    else:
        d[v] = u
        for t, c in G[v] :
            if d[t] == 10**9:
                f(t, u+c)
            else:
                if d[t] != u+c:
                    flag = False
                    
for i in range(1, N+1):
    if d[i] == 10**9:
        f(i, 0)
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 128888
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;
    char key[] = {'(', ')'};
    rep(j, 2) {
        {   
            int cnt = 0;
            rep(i, sz(s)) {
                if (s[i] == key[j]) {
                    cnt++;
                } else {
                    if (cnt > 0) {
                        cnt--;
                    }
                }
            }
            s += string(cnt, key[1-j]);
        }
        reverse(s.begin(), s.end());
    
    }
    cout << s << endl;
}

Measured memory_bytes: 256
n=int(input())
p=list(map(int,input().split()))
c=0
a=[]
b=[]
for i in range(n):
    if p[i]!=i+1:
        c+=1
        a.append(i+1)
        b.append(p[i])
if c==0:
    print("YES")
elif c==2:
    if a[0]==b[1]:
        print("YES")
    else:
        print("NO")
else:
    print("NO")


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const double PI = 3.1415926535897932;
const int MOD = 1e9 + 7;

vector<pair<ll, ll>> prime_factorize(ll n) {
  vector<pair<ll, ll>> res;
  for (ll i = 2; i * i <= n; i++) {
    if (n % i != 0) continue;
    ll ex = 0;
    while (n % i == 0) {
      ++ex;
      n /= i;
    }
    res.push_back({i, ex});
  }
  if (n != 1) res.push_back({n, 1});
  return res;
}

//cin.tie(0);ios::sync_with_stdio(false);
int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << 1 << endl;
    return 0;
  }
  vector<ll> primes;
  for (auto v : prime_factorize(n)) {
    for (ll i = 0; i < v.second; i++) {
      primes.push_back(v.first);
    }
  }
  vector<ll> ans;
  ll tmp1, tmp2;
  for (int bit = 0; bit < 1 << primes.size(); bit++) {
    tmp1 = tmp2 = 1;
    for (int j = 0; j < primes.size(); j++) {
      if (bit & 1 << j) {
	tmp1 *= primes[j];
      } else {
	tmp2 *= primes[j];
      }
    }
    ans.push_back(max(to_string(tmp1).size(), to_string(tmp2).size()));
  }

  cout << *min_element(ans.begin(), ans.end()) << endl;
  return 0;
}


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

using namespace std;

#define ll long long

int main() {
	int n;
	cin>>n;
	string s;
	cin>>s;
	int countWhite = 0;
	for(int i=0;i<n;i++){
		if(s[i] == 'R'){
	countWhite++;
}
}
int there = 0;
for(int i=0;i<countWhite;i++){
	if(s[i]=='R')
		there++;
}
cout<<countWhite - there;
	return 0;
}



Measured memory_bytes: 3752
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  ll n,m;
  cin>>n>>m;
  vll a(m+1);
  rep(i,n){
    ll k;
    cin>>k;
    rep(j,k){
      ll d;
      cin>>d;
      a[d]++;
    }
  }
  ll ans=0;
  rep(i,m+1){
    if(a[i]==n){
      ans++;
    }
  }
  COUT(ans);
}

Measured memory_bytes: 256
import sys
from time import time
import random

input = sys.stdin.readline
D = int(input())
C = [int(c) for c in input().split()]
S = [[int(s) for s in input().split()] for _ in range(D)] 
Ans = [int(i) % 26 + 1 for i in range(D)]

def change(point): #i番目をランダムに変更する
    ci = random.randint(0, D-1)
    contest = random.randint(1, 26)
    before = Ans[ci]
    Ans[ci] = contest
    newPoint = calcScore()
    if point > newPoint:
        Ans[ci] = before
    else:
        point = newPoint
    return


def calcScore():
    Last = [0] * 26
    point = 0
    for i, a in enumerate(Ans):
        point += S[i][a - 1]
        Last[a-1] = i + 1
        penalty = 0
        for j in range(26):
            penalty += C[j] * (i + 1 - Last[j])
        point -= penalty
    return point

def solve():
    start = time()
    point = calcScore()

    while time() - start < 1.8:
        change(point)

    print(*Ans, sep="\n") 
   
    return 0

if __name__ == "__main__":
    solve()

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

int main()
{
    int N;
    cin >> N;
    int A[N], B[N];
    for(int i = 1; i <= N; i++){
        B[i] = 0;
    }
    for(int i = 2; i <= N; i++){
        cin >> A[i];
        B[A[i]]++;
    }
    for(int i = 1; i <= N; i++){
        cout << B[i] << endl;
    }
}


Measured memory_bytes: 5204
#include <cassert>
#include <algorithm>
#include <array>
#include <bitset>
#include <cctype>
#include <cstdint>
#include <cmath>
#include <complex>
#include <chrono>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
#include <random>
#include <memory>
#include <utility>
#include <limits>
 
#define rep(i, a, b) for (long long i = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

void debug_out(){std::cerr<<std::endl;}

template<typename Head,typename... Tail>
void debug_out(Head h,Tail... t){
  std::cerr<<" "<<h;
  debug_out(t...);
}
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
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);}
 
long long pow_mod(long long a, long long b, long long mod=-1) {
  if(b==0)return 1;
  if ((a == 0)||(mod!=-1&&(a+mod)%mod==0))return 0;
  long long x = 1;
  while (b > 0) {
    if (b & 1)x = (mod!=-1)?(x * a) % mod:x*a;
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}

const long long MOD = 998244353;
// const long long MOD = 1e9 + 7;

using ll = long long;
using P=std::pair<long long,long long>;

// UnionFind 0-indexed
class UnionFind {
  private:
  std::vector<long long> uni;
  long long num,group;

  public:
  UnionFind(long long s) : uni(s, -1), num(s) ,group(s){}

  //頂点aが所属するグループ
  long long root(long long a) {
    if (uni[a] < 0) {
      return a;
    }
    return uni[a] = root(uni[a]);
  }

  // a,bをつなげる
  bool connect(long long a, long long b) {
    a = root(a);
    b = root(b);
    if (a == b) {
      return false;
    }

    group--;

    if (uni[a] > uni[b]) {
      std::swap(a, b);
    }

    uni[a] += uni[b];
    uni[b] = a;
    return true;
  }

  // a,bが同グループか確認
  bool isConnect(long long a, long long b) { return root(a) == root(b); }

  // aが属するグループの要素数
  long long size(long long a) { return -uni[root(a)]; }

  //グループ数を返す
  long long groups() {return group;}
};

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

  ll n,m;
  std::cin>>n>>m;

  UnionFind uni(n);

  rep(i,0,m){
    ll x,y,z;
    std::cin>>x>>y>>z;
    x--;y--;
    if(!uni.isConnect(x,y))uni.connect(x,y);
  }

  std::cout<<uni.groups()<<"\n";

  return 0;
}


Measured memory_bytes: 1024
using System;
class Program{
	public static void Main(){
		string str = Console.ReadLine();
		double A = Char.GetNumericValue(str[0]);
		double B = Char.GetNumericValue(str[1]);
		double C = Char.GetNumericValue(str[2]);
		double D = Char.GetNumericValue(str[3]);
		double B2, C2, D2;
		int f = 0;
		for (int p = 0; p <= 1; p++ ){
			if (f == 1)
				break;
			for (int q = 0; q <= 1; q++ ){
				if (f == 1)
					break;
				for (int r = 0; r <= 1; r++ ){
					B2 = Math.Pow(-1,p) * B;
					C2 = Math.Pow(-1,q) * C;
					D2 = Math.Pow(-1,r) * D;
					if (A + B2 + C2 + D2 == 7){
						string B3 = (B2 >= 0) ? "+" + B : "-" + B;
						string C3 = (C2 >= 0) ? "+" + C : "-" + C;
						string D3 = (D2 >= 0) ? "+" + D : "-" + D;
						Console.WriteLine("{0}{1}{2}{3}=7",A,B3,C3,D3);
						f = 1;
						break;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 13268
#include<iostream>
#include<vector>
#define int long long
using namespace std;
const int N=1e5+1;
const int inf=1e18+1;
int dp[101][N],w[N],v[N];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,i,j,k,z,max1=0;
	cin>>n>>z;
	for(i=1;i<=n;i++){
		cin>>w[i]>>v[i];
	}
	for(i=1;i<=100000;i++){
		dp[0][i]=inf;
	}
	for(i=1;i<=n;i++){
		for(j=0;j<=100000;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=v[i]){	
				dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
			}
			if(i==n&&dp[i][j]<=z){
				max1=max(max1,j);
			}
		}
	}
	cout<<max1;
}


Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;}
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;



int main()
{
        ll N;
        cin >> N;
        vll T(N+1);
        rep(i, 1, N+1) cin >> T[i];
        ll total = accumulate(all(T), 0LL);
        ll M;
        cin >> M;
        rep(i, 0, M) {
                ll p, x;
                cin >> p >> x;
                cout << total - T[p] + x << endl;
        }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

char mar[2] = {'+','-'};

int main()
{
	int tmp;cin >> tmp;
	int a,b,c,d;
	
	d = tmp % 10;tmp /= 10;
	c = tmp % 10;tmp /= 10;
	b = tmp % 10;tmp /= 10;
	a = tmp;
	
	REP(i,2)REP(j,2)REP(k,2)
	{
		int aa = a;
		if(i == 0)
		{
			aa += b;
		}
		else
		{
			aa -= b;
		}
		if(j == 0)aa += c;
		else aa -= c;
		if(k == 0)aa += d;
		else aa -= d;
		
		if(aa == 7)
		{
			cout << a << mar[i] << b << mar[j] << c << mar[k] << d << "=7" << endl;
			return 0;
			
		}
	}
	
	
	return 0;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> vpll;
typedef pair<ll, ll> pll;
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define yes(a) printf(a ? "yes\n" : "no\n")
#define Yes(a) printf(a ? "Yes\n" : "No\n")
#define YES(a) printf(a ? "YES\n" : "NO\n") 
const long double PI = acos(-1);
const long long INF = (1 << 30);
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(const ll a, const ll b){return ((a)+(b)-1)/b;}

ll h, w;
string s[51];
ll dist[51][51];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
	
  cin >> h >> w;
  for(ll i = 0; i < h; i++) cin >> s[i];

  ll cntw = 0;
  for(ll i = 0; i < h; i++){
    for(ll j = 0; j < w; j++){
      if(s[i][j] == '.') cntw++;
    }
  }

  for(ll i = 0; i < 51; i++){
    for(ll j = 0; j < 51; j++) dist[i][j] = INF;
  }
  queue<pll> q;
  q.push(make_pair(0, 0));
  dist[0][0] = 1;
  while(!q.empty()){
    pll p = q.front(); q.pop();
    ll dx[4] = {0, 1, 0, -1};
    ll dy[4] = {1, 0, -1, 0};
    for(ll i = 0; i < 4; i++){
      ll nx = p.first + dx[i], ny = p.second + dy[i];
      if(nx < 0 || nx >= h || ny < 0 || ny >= w || dist[nx][ny] <= dist[p.first][p.second]+1 || s[nx][ny] == '#') continue;
      q.push(make_pair(nx, ny));
      dist[nx][ny] = dist[p.first][p.second] + 1;
    }
  }

  if(dist[h-1][w-1] == INF) cout << -1 << endl;
  else cout << cntw - dist[h-1][w-1] << endl;
	return 0;
}

Measured memory_bytes: 256
for e in iter(input,'0'):
 a=list(tuple(map(int,input().split())) for _ in range(int(e)))
 s,t=a[0]
 b={tuple(map(int,input().split())) for _ in range(int(input()))}
 for x,y in b:
  flag = True
  for u,v in a[1:]:
   if(x+u-s,y+v-t)not in b:
    flag = False
    break
  if flag == True:
   print(x - s, y - t)
   break


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

int main(){
	ll n, k;
	cin>>n>>k;
	vector<ll> h(n);
	ll i;
	for(i=0;i<n;i++)
		cin>>h[i];
	vector<ll> dp(n, 1e15);
	dp[0] = 0;
	for(i=1;i<n;i++){
		ll j = max(0LL, i-k);
		while(j<i){
			dp[i] = min(dp[i], dp[j]+abs(h[i]-h[j]));
			j++;
		}
	}
	cout<<dp[n-1]<<"\n";
	return 0;
}

Measured memory_bytes: 4820
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
vpint adj[100001];
int d[100001],color[100001],p[100001];
int N;
void dijkstra(int st){
	priority_queue<pint> PQ;//辺の長さのオーバーフローに注意！
	rep(i,N){
		d[i]=INF;
		color[i]=0;
	}
	d[st]=0;
	color[st]=1;
	PQ.push(mp(0,st));
	while(!PQ.empty()){
		pint f=PQ.top();
		PQ.pop();
		int u=f.second;
		color[u]=2;
		if(d[u]< -f.first) continue;
		rep(j,adj[u].size()){
			int v=adj[u][j].first;
			if(color[v]==2) continue;
			if(d[v]>d[u]+adj[u][j].second){
				d[v]=d[u]+adj[u][j].second;
				p[v]=u;
				PQ.push(mp(-d[v],v));
				color[v]=1;
			}
		}
	}
}
int main(){
	int M;
	int A[200001],B[200001];
	scan(N>>M);
	rep(i,M){
		scan(A[i]>>B[i]);
		A[i]--; B[i]--;
		adj[A[i]].push_back({B[i],1});
		adj[B[i]].push_back({A[i],1});

	}
	dijkstra(0);
	prin("Yes");
	rep1(i,N-1){
		prin(p[i]+1);
	}
	return 0;
}


Measured memory_bytes: 15368
a, b, x = gets.chomp.split(' ').map(&:to_f)
x = x / a

if x >= (a * b)/2
  s = a * b - x
  l = 2 * s / a
  r = Math.atan(l / a) * 180 / Math::PI
else
  l = 2 * x / b
  r = Math.atan(b / l) * 180 / Math::PI
end

puts r


Measured memory_bytes: 14480
// C++ program to demonstrate __builtin_popcount() 
#include <iostream> 
#include <math.h>
using namespace std; 

int main() 
{ 
        int n;
        cin>>n;
        int ans[60000]={0};
        for(int i=1;i<=100;i++)
        {
            for(int j=1;j<=100;j++)
            {
                for(int k=1;k<=100;k++)
                {
                    ans[i*i+j*j+k*k+i*j+j*k+k*i]++;
                }
            }
        }
        for(int i=1;i<=n;i++)
            cout<<ans[i]<<"\n";
    return 0; 
} 


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

a = list(map(int, input().split()))
box = [0]*n
for i in range(n,0,-1):
    sum_box = 0
    for j in range(i,n+1,i):
        sum_box+=box[j-1]
    if sum_box%2!=a[i-1]:
        box[i-1]+=1
 
print(sum(box))
if sum(box):
    ans = []
    for i, x in enumerate(box):
        if x:
            ans.append(i+1)
    print(*ans)

Measured memory_bytes: 68700
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Feb  9 20:41:09 2019

@author: shinjisu
"""


# 2019/2/9 Yahoo
def getInt(): return int(input())


def getIntList(): return [int(x) for x in input().split()]


def getIntLines(n): return [int(input()) for i in range(n)]


def zeros(n): return [0]*n


def db(x):
    global debug
    if debug:
        print(x)


def probA():
    N, K = getIntList()
    db((N, K))
    if (N+1)//2>=K:
        print('YES')
    else:
        print('NO')


def probB():
    a, b = zeros(3), zeros(3)
    db((a,b))
    for i in range(3):
        a[i], b[i] = getIntList()
    db((a,b))
    c = set([])
    e = zeros(5)
    for i in range(3):
        c.add(a[i])
        c.add(b[i])
        e[a[i]] += 1
        e[b[i]] += 1
    db((c,e))
    c0,c1,c2,c3,c4=0,0,0,0,0
    for i in range(1, 5):
        if e[i]==0:
            c0 += 1
        elif e[i] == 1:
            c1 += 1
        elif e[i] == 2:
            c2 += 1
        elif e[i] == 3:
            c3 += 1
        else:
            c4 += 1
    db((c0,c1,c2,c3,c4))
    if c1 == 2 and c2 == 2: 
        print('YES')
    else:
        print('NO')


def probC():
    return 0


debug = False
probB()


Measured memory_bytes: 3188
import sys

str = sys.stdin.readlines()

N = int(str[0])
Hs = str[1].split()

Hnum = []
for Hstr in Hs:
    Hnum.append(int(Hstr))
Hnum.append(Hnum[N-1] + 1)

j = 0
tmpcount = 0
maxcount = 0
for i in range(1,N+1):
    if Hnum[i]>Hnum[i-1]:
        tmpcount = i - j - 1
        if tmpcount > maxcount:
            maxcount = tmpcount
        j = i

print(maxcount)


Measured memory_bytes: 15284
// Problem : E - Coprime
// Contest : AtCoder - AtCoder Beginner Contest 177
// URL : https://atcoder.jp/contests/abc177/tasks/abc177_e
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)
#include <bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define fr(i,a,b) for(int i=a;i<b;i++)
#define frr(i,a,b) for(int i=a;i>=b;i--)
//vector
#define pb push_back
#define vi vector<int>
#define vl vector<ll>
#define pp pop_back
//pair
#define pi pair<int ,int >
#define mk make_pair
#define ff first
#define ss second
//set
#define si set<int>
#define sit set<int>::iterator 
using namespace std;
#include <bits/stdc++.h> 
using namespace std; 
int findMaxGCD(int arr[], int n) 
{ 
    int high = 0; 
    for (int i = 0; i < n; i++) 
        high = max(high, arr[i]); 
    int count[high + 1] = {0}; 
    for (int i = 0; i < n; i++) 
        count[arr[i]]++; 
    int counter = 0; 
 
    for (int i = high; i >= 1; i--) 
    { 
        int j = i; 
       counter = 0; 
        while (j <= high) 
        { 
  
            if(count[j] >=2) 
               return j; 
  
           else if (count[j] == 1)          
                counter++;          
            j += i; 
            if (counter == 2)          
                return i; 
        } 
    } 
} 
int main() 
{ 
 
fast;
    int n;cin>>n;
    int a[n],tt=0;
    fr(i,0,n)
    {
    	cin>>a[i];
    	if(i==0)
    	{
    		tt=a[i];
    	}
    	else
    	{
    		tt=__gcd(a[i],tt);
    	}
    }
    int t= findMaxGCD(a, n); 
    
    if(t==1) cout<<"pairwise coprime";
  	else if(tt==1) cout<<"setwise coprime";
    else cout<<"not coprime";
    
  
    return 0; 
} 

Measured memory_bytes: 11448
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = LLONG_MAX;

int n;
int E[310000] = {};
int W[310000] = {};
string s;

int main()
{
    cin >> n >> s;
    if (s[0] == 'E')
        E[0] = 1;
    else
        W[0] = 1;
    for (int i = 1; i < n; i++)
    {
        E[i] = E[i - 1] + (s[i] == 'E' ? 1 : 0);
        W[i] = W[i - 1] + (s[i] == 'W' ? 1 : 0);
    }
    int ans = INT_MAX;
    for (int i = 0; i < n; i++)
    {
        ans = min(ans, W[i - 1] + (E[n - 1] - E[i]));
    }
    cout << ans << endl;
}


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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

main(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<string> s(h);
  cin>>s;
  auto sum = vec<ll>(h+1,w+1);
  rep(i,h)rep(j,w){
    sum[i+1][j+1] = (s[i][j]=='1');
  }
  rep(i,h)rep(j,w){
    sum[i + 1][j + 1] += sum[i + 1][j] + sum[i][j + 1] - sum[i][j];
  }

  auto get = [&](int sy, int sx, int ty, int tx) {
   return sum[ty][tx] - sum[ty][sx] - sum[sy][tx] + sum[sy][sx];
  };
  auto chk = [&](auto const& div,int px,int x){
    int n = div.size();
    ll tmp = 0;
    rep(i,n-1){
      chmax(tmp,get(div[i],px,div[i+1],x));
    }
    return tmp;
  };
  ll ans = INF;
  for(int i=0;i<(1<<(h-1));++i){
    bitset<11> b(i);
    vector<ll> div;
    div.emplace_back(0);
    rep(j,10)if(b[j])div.emplace_back(j+1);
    div.emplace_back(h);
    int px=0;
    ll tmp=b.count();
    for(int x=1;x<=w;++x){
      auto v = chk(div,px,x);
      if(v>k){
        if(abs(x-px)==1){
          tmp = INF;
          break;
        }
        tmp++;
        px = x-1;
      }
    }
    if(chk(div,px,w)>k)tmp=INF;
    chmin(ans,tmp);
  }
  cout<<(ans)<<endl;
  
}


Measured memory_bytes: 384
#include<stdio.h>
int dp[101][4][2];//day, type, ツづつづδつォツつゥツつス
int type[101];
int main(){
	int a,b;
	int MOD=10000;
	scanf("%d%d",&a,&b);
	for(int i=0;i<b;i++){
		int c,d;
		scanf("%d%d",&c,&d);
		type[c]=d;
	}
	dp[0][0][0]=1;
	for(int i=1;i<=a;i++){
		if(type[i]){
			dp[i][type[i]][0]=dp[i-1][0][0];
			if(type[i]==1)dp[i][type[i]][1]+=dp[i-1][1][0];
			else dp[i][type[i]][0]+=dp[i-1][1][1]+dp[i-1][1][0];
			if(type[i]==2)dp[i][type[i]][1]+=dp[i-1][2][0];
			else dp[i][type[i]][0]+=dp[i-1][2][1]+dp[i-1][2][0];
			if(type[i]==3)dp[i][type[i]][1]+=dp[i-1][3][0];
			else dp[i][type[i]][0]+=dp[i-1][3][1]+dp[i-1][3][0];
		}else{
			for(int j=1;j<=3;j++){
				dp[i][j][0]=dp[i-1][0][0];
				for(int k=1;k<=3;k++){
					if(k!=j){
						dp[i][j][0]+=dp[i-1][k][0]+dp[i-1][k][1];
					}else dp[i][j][1]+=dp[i-1][k][0];
				}
			}
		}
		dp[i][1][0]%=MOD;
		dp[i][1][1]%=MOD;
		dp[i][2][0]%=MOD;
		dp[i][2][1]%=MOD;
		dp[i][3][0]%=MOD;
		dp[i][3][1]%=MOD;
	}
	printf("%d\n",(dp[a][1][0]+dp[a][1][1]+dp[a][2][0]+dp[a][2][1]+dp[a][3][0]+dp[a][3][1])%MOD);
}

Measured memory_bytes: 0
import numpy as np


N, M = map(int, input().split())
A, B = list(), list()
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
A = np.array(A)
B = np.array(B)

n_bins = 0
cost = 0
indices = np.argsort(A)
for idx in indices:
    # enough bins @idx
    if n_bins + B[idx] > M:
        cost += A[idx] * (M - n_bins)
        break
    # buy all bins
    else:
        n_bins += B[idx]
        cost += A[idx] * B[idx]
print(cost)

Measured memory_bytes: 20816
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <chrono>
#include <random>

using namespace std;

#define int long long
#define ll long long
//#define double long double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

const int INF = 2e9;
const int MB = 20;
const int MOD = 1e9 + 7;

void solve() {
    int n;
    cin >> n;
    map<string, int> mp;
    int mx = 0;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mp[s]++;
        mx = max(mx, mp[s]);
    }

    for (auto& p : mp) {
        if (p.second == mx) {
            cout << p.first << '\n';
        }
    }
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    solve();
}

Measured memory_bytes: 23936
#include<iostream>
#include<string>

using namespace std;

#define DATE_MEIJI_S 18680908
#define DATE_MEIJI_F 19120729
#define DATE_TAISHO_S 19120730
#define DATE_TAISHO_F 19261224
#define DATE_SHOWA_S 19261225
#define DATE_SHOWA_F 19890107
#define DATE_HEISEI_S 19890108

class CEra{
public:
	CEra(){}
	void Set(string name, int st, int fin){
		this->name = name;
		this->st = st;
		this->fin = fin;
	}
	void outputString(int y, int m, int d){
		cout << name << ' ' << y - st/10000 + 1 << ' ' << m << ' ' << d << endl; 
	}
	bool dayOf(int date){
		return st <= date && date <= fin;
	}
private:
	string name;
	int st, fin; // yyyymmdd
};

int main(void){
	CEra eras[4];

	eras[0].Set("meiji", DATE_MEIJI_S, DATE_MEIJI_F);
	eras[1].Set("taisho", DATE_TAISHO_S, DATE_TAISHO_F);
	eras[2].Set("showa", DATE_SHOWA_S, DATE_SHOWA_F);
	eras[3].Set("heisei", DATE_HEISEI_S, 100000000);

	while( true ){
		int date = 0;
		int y, m, d;
		bool bElseEra = true;

		cin >> y >> m >> d;
		if( cin.eof() ) break;

		date += y * 10000 + m * 100 + d;

		for(int i = 0; i < sizeof(eras)/sizeof(*eras); i++){
			if( eras[i].dayOf( date ) ){
				eras[i].outputString(y,m,d);
				bElseEra = false;
			}
		}
		if( bElseEra ) cout << "pre-meiji" << endl;
	}
	return 0;
}

Measured memory_bytes: 0
/*痛みを受け取れ，痛みを知れ*/
#include<bits/stdc++.h>
#define f(i,a,b) for(register int i=a;i<=b;++i)
#define ff(i,a,b) for(register int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 5e5 + 5;
int a[N];
int main()
{
	//freopen("in.txt", "r", stdin);
	int n, k;
	while (cin >> n >> k)
	{
		f(i, 1, n)scanf("%d", &a[i]);
		int l = 1, r = k + 1;
		while (r <= n)
		{
			if (a[r] > a[l])puts("Yes");
			else puts("No");
			l++;
			r++;
		}
	}
	return 0;
}

Measured memory_bytes: 4540
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using lim = numeric_limits<T>;
template <typename T> istream& operator>>(istream& is, vector<T>& a) { for(T& x : a) { is >> x; } return is; }
template <typename X, typename Y> istream& operator>>(istream& is, pair<X, Y>& p) { return is >> p.first >> p.second; }
enum class event_t { start, end, query };
struct event {
    event_t type;
    int pos, val;
};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    vector<event> events;
    for(int i = 0; i < n; i++) {
        int s, t, x;
        cin >> s >> t >> x;
        events.push_back({event_t::start, s - x, x});
        events.push_back({event_t::end, t - x, x});
    }
    for(int i = 0; i < q; i++) {
        int d;
        cin >> d;
        events.push_back({event_t::query, d, i});
    }
    vector<int> ans(q);
    sort(events.begin(), events.end(), [](auto& e1, auto& e2) {
        return pair{e1.pos, e1.type} < pair{e2.pos, e2.type};
    });
    multiset<int> s;
    for(auto& e : events) {
        if(e.type == event_t::start) {
            s.insert(e.val);
        } else if(e.type == event_t::end) {
            s.erase(s.find(e.val));
        } else {
            ans[e.val] = s.empty() ? -1 : *s.begin();
        }
    }
    for(int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 20392
s=input()
s=list(s)

if s[0]==s[1]==s[2]==s[3]:
  print('No')
elif s[0]==s[1] and s[2]==s[3]:
    print('Yes')
elif s[0]==s[2] and s[1]==s[3]:
    print('Yes')
elif s[0]==s[3] and s[1]==s[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8996
#include<bits/stdc++.h>
#define ll long long
#define f first
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define all(v) v.begin(),v.end()
#define mem(v,x) memset(v,x,sizeof(v))
#define ar array
#define N 100005

using namespace std;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	ll n;
	cin>>n;
	vector<ll> v;
	for(ll i=-500;i<501;i++){
        v.pb(pow(i, 5));
	}
	map<ll,ll> u;
	for(int i=0;i<v.size();i++){
        u[v[i]] = i-500;
	}
	for(int i=0;i<v.size();i++){
        ll rem = v[i]-n;
        if(u.find(rem)!=u.end()){
            cout<<i-500<<' '<<u[rem];
            return 0;
        }
	}
	return 0;
}


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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)
int main(){
	int n,m;
	cin >> n >> m;
	int c[n] = {};
	int l,r;
	//道路を入力
	for(int i = 0; i < m; i++){
		cin >> l >> r;
		//登場した都市をカウント
		c[l-1]++;
		c[r-1]++;
	}
	//カウントしてあるので順番に出力
	for(int i = 0; i < n; i++){
		cout << c[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
//#include <cstdio>
//#include <functional>
#include <iostream>
//#include <cfloat>
//#include <climits>
//#include <cstdlib>
//#include <cstring>
//#include <cmath>
//#include <map>
//#include <queue>
//#include <set>
//#include <sstream>
//#include <stack>
#include <string>
//#include <time.h>
#include <vector>
//#include <random>
//#include <unordered_set>
//#include <complex>
#define rt0 return 0
using namespace std;
int main()
{
	string s;
	bool b[3]={false};
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='a') b[0]=true;
		if(s[i]=='b') b[1]=true;
		if(s[i]=='c') b[2]=true;
	}
	if(b[0] and b[1] and b[2]) cout<<"Yes";
	else cout<<"No";
    rt0;
}

Measured memory_bytes: 256
#include <iostream>

#include <cstdio>

#include <algorithm>

#include <set>

#include <string>

#include <cstring>

#include <cmath>

#include <map>

#include <stack>

#define N 1005

using namespace std;

typedef long long ll;

int a[305][305];

struct node

{

	int x;

	int y;

}p[90005];

int ans[90005];

int main()

{

	int h, w, d, len;

	scanf("%d%d%d", &h, &w, &d);

	for (int i = 1; i <= h; i++)

		for (int j = 1; j <= w; j++) {

			scanf("%d", &a[i][j]);

			int n = a[i][j];

			p[n].x = i;

			p[n].y = j;

		}

	int q;

	len = h * w;

	scanf("%d", &q);

	for (int i = 1; i <= d; i++)

	{

		int l = i, r = len, sum = 0;

		ans[i] = 0;

		while (l <= r - d)

		{

			sum = sum + abs(p[l].x - p[l + d].x) + abs(p[l].y - p[l + d].y);

			l = l + d;

			ans[l] = sum;

		}



	}

	while (q--)

	{

		int l, r;

		scanf("%d%d", &l, &r);

		printf("%d\n", ans[r] - ans[l]);

	}

}


Measured memory_bytes: 2560
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
#include <utility>
#include <algorithm>
using namespace std;


typedef complex<double> Point;
typedef pair<Point, Point> Line;
#define EPS 1e-9
#define INF 1000000000

double dis(Point a, Point b){ return abs(a - b); }
double dot(Point a, Point b){ return a.real() * b.real() + a.imag() * b.imag(); }
double cross(Point a, Point b){ return a.real() * b.imag() - a.imag() * b.real(); }
int ccw(Point a, Point b, Point c){
  if(cross(b - a, c - a) > EPS) return 1;
  if(cross(b - a, c - a) < -EPS) return -1;
  if(dot(b - a, c - a) < -EPS) return 2;
  if(dis(a, b) + EPS < dis(c, a)) return -2;
  return 0;
}
int ccw(Line a, Point b){ return ccw(a.first, a.second, b); }

bool SegmentCross(Line a, Line b){
  return ccw(a, b.first) * ccw(a, b.second) == -1
    && ccw(b, a.first) * ccw(b, a.second) == - 1;
}

Point MiddlePoint(Point a, Point b){
  double x = (a.real() + b.real()) / 2;
  double y = (a.imag() + b.imag()) / 2;
  return Point(x, y);
}

Line Equidistant(Point a, Point b, double r = -1){
  Point m = MiddlePoint(a, b);
  double m_dis = dis(m, a);
  double slope = (b.real() - a.real()) / (a.imag() - b.imag());
  
  if(r <= EPS){ r = m_dis * 2; }
  
  if(r <= m_dis + EPS){ return make_pair(Point(0, 0), Point(0, 0)); }

  double target_dis = r * r - m_dis * m_dis;
  double x = sqrt(target_dis / (1 + slope * slope));
  double y = slope * x;
  
  Point s(m.real() + x, m.imag() + y);
  Point t(m.real() - x, m.imag() - y);
  
  return make_pair(s, t);
}


int main(void){
  while(true){
    int n;
    cin >> n;
    if(n == 0){ break; }

    double x, y;
    vector<Point> P;
    for(int i = 0; i < n; i++){
      cin >> x >> y;
      P.push_back(Point(x, y));
    }

    int ans = 1;
    for(int i = 0; i < n; i++){
      for(int j = i + 1; j < n; j++){
        Line tmpLine = Equidistant(P[i], P[j], 1 - EPS);
        if(tmpLine.first == tmpLine.second){ continue; }

        Point center[] = {tmpLine.first, tmpLine.second};
        for(int l = 0; l < 2; l++){
          int count = 0;
          for(int k = 0; k < n; k++){
            if(dis(center[l], P[k]) <= 1.0 + EPS){
              ++count;
            }
          }
          
          ans = max(ans, count);
        }
      }
    }

    // ??????
    cout << ans << endl;
     
  }

  return 0; 
}

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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

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

    vector<int> sum(N + 1);
    sum[0] = 0;
    rep(i, N) sum[i + 1] = (sum[i] + A[i]) % K;

    map<int, int> m;
    queue<int> q;
    ll ans = 0;
    rep(i, N + 1) {
        ans += m[ sum[i] ];
        m[ sum[i] ]++;
        q.push(sum[i]);
        if (q.size() == K) {
            m[ q.front() ]--;
            q.pop();
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 12032
import std.stdio;
import std.algorithm;
import std.conv;
import std.range;
import std.string;
import std.math;

void main() {
	long n = readln.chomp.to!int;
	long[] as = readln.chomp.split(' ').map!(s => s.to!long).array;
	long negc;
	long amin = long.max;
	long total = 0;
	foreach(a;as){ 
		if (a < 0) --negc;
		amin = min(amin, abs(a));
		total += abs(a);
	}
	if (negc % 2 == 0) {
		write(total);
	}
	else {
		write(total - 2*amin);
	}
}


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


int main(){
    long long K;
    cin >> K;

    int Ans = -1;

    int repsept = 7;

    for(int i = 1;i <= K;i++){
        if(repsept % K == 0){
            Ans = i;
            break;
        }
        repsept = (repsept * 10 + 7) % K;
    }

cout << Ans << endl;

}


Measured memory_bytes: 3616
#include <cstdio>
#include <algorithm>

using namespace std;

int N, P, m = 1000000, ans;

int main() {
  scanf("%d", &N);
  for (int i = 0; i < N; i++) {
    scanf("%d", &P);
    if (P < m) {
      ans++;
      m = P;
    }
  }

  printf("%d", ans);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<long long,long long>
#define ii pair<int,int>
#define mod 1000000007
#define endl '\n'
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);

ll power(ll a,ll b){
	ll ans=1;
	while(b>0){
		if(b%2!=0){
			ans=(ans*a)%mod;
		}
		a=((a%mod)*(a%mod))%mod;
		b>>=1;
	}
	return ans;
}

void sieve(int n){
	bool prime[n+1];
	memset(prime,true,sizeof(prime));
	for(int p=2;p*p<=n;p++){
		if(prime[p]){
			for(int i=p*p;i<=n;i+=p)
				prime[i]=false;
		}
	}
	for(int p=2;p<=n;p++){
		if(prime[p])
			cout<<p<<" ";
	}
}

int main() {
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		int n;
		cin>>n;
		map<int,int> m;
		int a[n];
		int cnt=0;
		for(int i=0;i<n;i++){
			cin>>a[i];
			m[a[i]]++;
		}

		if(m.count(1)==true){
			if(m[1]!=1){
				cout<<0;				
			}
			else
				cout<<1;
			return 0;
		}

		for(int i=0;i<n;i++){
			if(m[a[i]]!=1)
				continue;
			bool flag=true;
			for(int j=2;j*j<=a[i];j++){
				if(a[i]%j!=0)
					continue;
				if(m.count(j)==true){
					flag=false;
					break;
				}
				if(j*j!=a[i]&&m.count(a[i]/j)==true){
					flag=false;
					break;
				}
			}
			if(flag)
				cnt++;
		}
		cout<<cnt;


	}
	return 0;
}

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

int main() {
  string s; cin >> s;
  string ans = "";
  rep(i, s.size()) {
    if (s[i] == 'B') {
      if (ans.size() != 0) {
        ans.erase(ans.end()-1);
      }
    }
    else {
      ans += s[i];
    }
  }
  cout << ans << endl;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, K;
  cin >> N >> K;
  vector<int64_t> X(N), Y(N), SX(N), SY(N);
  for (int i = 0; i < N; i++) {
    cin >> X[i] >> Y[i];
    SX[i] = X[i];
    SY[i] = Y[i];
  }
  sort(SX.begin(), SX.end());
  sort(SY.begin(), SY.end());
  int64_t res = (SX[N - 1] - SX[0]) * (SY[N - 1] - SY[0]);
  for (int ix = 0; ix < N; ix++) {
    for (int jx = ix + 1; jx < N; jx++) {
      for (int iy = 0; iy < N; iy++) {
        for (int jy = iy + 1; jy < N; jy++) {
          int cnt = 0;
          for (int i = 0; i < N; i++) {
            if (SX[ix] <= X[i] && X[i] <= SX[jx] && SY[iy] <= Y[i] &&
                Y[i] <= SY[jy])
              cnt++;
          }
          if (cnt >= K) res = min(res, (SX[jx] - SX[ix]) * (SY[jy] - SY[iy]));
        }
      }
    }
  }
  cout << res << '\n';
  return 0;
}


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


vector<int> par;
vector<bool> exists;

int n;
vector<int> cur;
vector<int> ops;

void make_move(int v){
	ops.push_back(v);
	int x = cur[0];
	while(true){
		swap(x, cur[v]);
		if(v == 0) break;
		v = par[v];
	}
	assert(x == cur[ops.back()]);
}

void solve(){
	while(true){
		vector<int> deg(n, 0);
		vector<int> ch(n, -1);
		for(int i = 0; i < n; i++){
			if(!exists[i]) continue;
			if(i > 0){
				deg[par[i]]++;
				ch[par[i]] = i;
			}
		}
		vector<bool> cur_step(n, false);
		for(int i = 0; i < n; i++){
			if(!exists[i]) continue;
			if(deg[i] == 0){
				int x = i;
				while(x > 0 && deg[x] <= 1){
					cur_step[x] = true;
					x = par[x];
				}
			}
		}

		vector<bool> up_tree(n, false);
		for(int i = 0; i < n; i++){
			if(exists[i]) up_tree[i] = true;
		}
		vector<bool> placed(n, false);
		while(up_tree[0]){
			int v = cur[0];
			if(cur_step[v]){
				int x = v;
				while(ch[x] != -1){
					x = ch[x];
				}
				while(placed[x]) x = par[x];
				assert(cur_step[x]);
				placed[x] = true;
				up_tree[x] = false;
				while(ch[x] != -1 && cur[ch[x]] < v){
					x = ch[x];
				}
				make_move(x);
			} else {
				for(int x = n-1; x >= 0; x--){
					if(up_tree[x]){
						up_tree[x] = false;
						make_move(x);
						break;
					}
				}
			}
		}

		for(int i = 0; i < n; i++){
			if(cur_step[i]){
				exists[i] = false;
				assert(cur[i] == i);
			}
		}
		int nexists = 0;
		for(int a : exists) nexists += a;
		if(nexists == 1) break;
	}
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> n;
	par.resize(n);
	par[0] = -1;
	for(int i = 1; i < n; i++) cin >> par[i];

	cur.resize(n);
	for(int i = 0; i < n; i++) cin >> cur[i];
	exists.assign(n, true);
	solve();
	cout << ops.size() << '\n';
	for(int a : ops){
		cout << a << ' ';
	}
	cout << '\n';
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N, K; cin >> N >> K;
  int p[N]; rep(i,N) cin >> p[i];
  sort(p,p+N);
  int retval = 0;
  rep(i,K) retval += p[i];
  cout << retval << endl;


  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 3600