akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fto(i, s, e) for (int i = (s); i <= (e); ++i)
#define fto1(i, s, e) for (int i = (s); i < (e); ++i)
#define fdto(i, s, e) for (int i = (s); i >= (e); --i)
#define fit(it, a) for (auto it = (a).begin(); it != (a).end(); ++it)
#define fat(i, a) for (auto i : (a))

#define ll long long
#define ii pair<int, int>
#define pll pair<ll, ll>
template<class T, class Cmp = less<T>> using oss = tree<T, null_type, Cmp, rb_tree_tag, tree_order_statistics_node_update>;

#define bc __builtin_popcountll
#define y1 ansdj
#define endl '\n'
#define ff first
#define ss second
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define bug(...) _bug(cout, __VA_ARGS__)
#define bugn(...) _bugn(#__VA_ARGS__, __VA_ARGS__)
#define buga(a, s, e) cout << '{'; fto (i, s, e) cout << a[i] << " }"[i == e]; cout << endl

template<class T1, class T2> ostream& operator<<(ostream &os, pair<T1, T2> const &v) {
    return os << '(' << v.ff << ", " << v.ss << ')';
}

template<typename T>
void _bug(ostream &os, T const &var) { os << var << endl; }

template<typename T, typename... Args>
void _bug(ostream &os, T const &var, Args const &... args) {
    os << var << ' ';
    _bug(os, args...);
}

template<typename... Args>
void _bugn(string const &s, Args const &... args) {
    auto split = [](string const &s, string const &delim) {
        int next, pos = 0;
        vector<string> res;
        while (1) {
            next = s.find(delim, pos);
            if (next == string::npos) break;
            res.push_back(s.substr(pos, next-pos));
            pos = next+sz(delim);
        }
        res.push_back(s.substr(pos));
        return res;
    };

    ostringstream os; _bug(os, args...);
    string tmp = os.str(); tmp.pop_back(); 
    vector<string> v1 = split(s, ", "), v2 = split(tmp, " ");
    fto1 (i, 0, sz(v1)) cout << '[' << v1[i] << ": " << v2[i] << "]" << " \n"[i == sz(v1)-1];
}

double const pi = acos(-1);
#define oo 1000000007
#define OO 1000000000000000003LL
int const maxn = 2e5+3;

int n, k, mod = 998244353;
ii a[maxn];
ll f[maxn];

void update(int idx, int val) {
    for (; idx <= n; idx += idx & -idx)
        f[idx] = (f[idx] + val) % mod;
}

ll get(int idx) {
    ll res = 0;
    for (; idx; idx -= idx & -idx)
        res = (res + f[idx]) % mod;
    return res;
}

#define multi_test 0
void _main() {
    cin >> n >> k;
    fto (i, 1, k) cin >> a[i].ff >> a[i].ss;
    update(1, 1); update(2, mod - 1);
    fto1 (i, 1, n) {
        ll res = get(i);
        fto (j, 1, k) {
            update(i+a[j].ff, res);
            update(i+a[j].ss+1, mod - res);
        }
    }
    bug(get(n));
}

int main() {
    #ifdef KITTENS
        freopen("main.inp", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

    int t = 1;
    if (multi_test) cin >> t;
    while (t--) {
        _main();
    }

    #ifdef KITTENS
        cerr << 0.001*clock() << endl;
    #endif
    return 0;
}

Measured memory_bytes: 5160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
//グリッド：（典型）dp,dfs,bfs,最短経路,その他
int main(){
    string s;cin >> s;
    int n=(int)s.size();
    s=s+"###";
    ll ans=0;
    int cnt=0;
    for(int i=0;i<n;i++){
        if(s[i]=='A') cnt++;
        else if(s[i]=='B'&&s[i+1]=='C'){
            ans+=cnt;
            i++;
        }
        else cnt=0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 772
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
      int a=sc.nextInt()+sc.nextInt();
      int b=sc.nextInt()+sc.nextInt();
      System.out.println((a==b)?"Balanced":(a>b)?"Left":"Right");
    }
}


Measured memory_bytes: 21844
N = int(input())
S = list(input())
s = []

for i in range(len(S)):
    S[i] = ord(S[i])

for item in S:
    if item + N > 90:
        s.append(chr(item + N - 26))
    else:
        s.append(chr(item + N))

out = "".join(s)

print(out)


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
using ll=long long;
using ld=long double;
using namespace std;
const ll mod=1e9+7;
pair<ll,ll> a[110000];
int main(){
  ll n,k,x=0,ans=0;
  cin>>n>>k;
  rep(i,0,n)cin>>a[i]F>>a[i]S;
  sort(a,a+n);
  while(k>0){
    if(k>a[x]S){k-=a[x]S;x++;}
    else {k=0;ans=a[x]F;}
  }
  cout<<ans;
}



Measured memory_bytes: 1792
import javax.xml.crypto.Data;
import java.util.*;
import java.io.*;

public class Main {
    public static int n;
    public static int MAX = 500000;
    public static long a[] = new long[MAX + 1];

    public static void main(String[] args) throws IOException {

        //??\???
        /*
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        */
        FastScanner sc = new FastScanner();
        PriorityQueue<Long> PQ = new PriorityQueue<Long>(Collections.reverseOrder());

        while (true) {
            String S = sc.next();
            if(S.equals("insert")) {
                long m = sc.nextLong();
                PQ.add(m);
            }
            if(S.equals("extract")) {
                System.out.println(PQ.poll());
            }
            if(S.equals("end")) break;
        }

        //??????
    }

}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}

Measured memory_bytes: 206156
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);

#define debug(x) (#x " : " + to_string(x))
#define debug_cout(x) (cout << #x << " : " << to_string(x) << endl)
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair((a), (b));
using namespace std;
using ll = long long;
//#define int long long
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = (int)2e9;

/*****/

int main()
{
	int N, D;
	cin >> N >> D;
	vector<vector<int>> X(N, vector<int>(D));
	rep(i, N)
	{
		rep(j, D)
		{
			cin >> X[i][j];
		}
	}

	int cnt = 0;
	for (int a = 0; a < N; a++)
	{
		for (int b = a + 1; b < N; b++)
		{
			ll dif = 0;
			for (int i = 0; i < D; i++)
			{
				dif += (X[a][i] - X[b][i]) * (X[a][i] - X[b][i]);
			}

			ll difsq = (ll)sqrt(dif);
			if (dif == difsq * difsq)
			{
				cnt++;
				//debug_cout(a);
				//debug_cout(b);
				//debug_cout(dif);
			}
		}
	}

	cout << cnt << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
#define int long long
using namespace std;
const int maxn = 2e5+5;
typedef pair<int,int> pii;

int dp[maxn][105] = {};
pii item[maxn];

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n, w;
	cin >> n >> w;
	for (int i = 1; i <= n; i++) cin >> item[i].X >> item[i].Y;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= w; j++) {
			dp[j][i] = dp[j][i-1];
			if (j >= item[i].X) {
				dp[j][i] = max(dp[j][i-1], dp[j-item[i].X][i-1] + item[i].Y);
			}
		}
	}
	cout << dp[w][n] << "\n";
}

Measured memory_bytes: 85480
#define NDEBUG 1

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

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

typedef long long ll;

int main(){
    int n;
    while(cin >> n && n){
        vector<vector<int>> g(5,vector<int>(n));
        rep(i,n)rep(j,5) cin >> g[j][i];
        rep(i,5) reverse(begin(g[i]), end(g[i]));
        // rep(i,5)rep(j,5) cin >> g[i][j];
        // rep(i,5) reverse(begin(g[i]), end(g[i]));
        // rep(i,5)rep(j,i) swap(g[i][j], g[j][i]);
        int ans = 0, add = -1;
        while(add){
            add = 0;
            rep(i,5){
                rep(j,g[i].size()){
                    int ni = i;
                    if(g[i][j] == -1) continue;
                    while(ni < 5 && j < (int)g[ni].size() && g[ni][j]==g[i][j]) ni++;
                    if(ni - i < 3) continue;
                    add += g[i][j] * (ni-i);
                    // printf(" %d %d %d\n", j,i,ni);
                    loop(k,i,ni) g[k][j] = -1;
                }
            }
            for(auto & r:g) r.erase(remove(begin(r), end(r),-1), r.end());
            ans += add;
            assert(add > 0);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1212
n = 1000000

# ??¨????????????????????????
# ?????????????????´??°??\????????¨???????´???°???????????????
ns = (n**0.5).to_i + 1
is_prime = [false, false] + [true]*(n-1)
2.upto(ns) do |i|
  next if !is_prime[i]
  (i*i).step(n, i) do |j|
    is_prime[j] = false
  end
end

count = 0
list = (0..n).map do |i|
  count += 1 if is_prime[i]
  count
end

while gets
  puts list[$_.to_i]
end

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

int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  
  double thetaA, thetaB;
  thetaA = 2 * M_PI * (60 * H + M) / 720;   
  thetaB = 2 * M_PI * M /60;
  cout << fixed << setprecision(12) << sqrt(A * A + B * B - 2 * A * B * cos (thetaA - thetaB)) << endl;
  
}

Measured memory_bytes: 4228
#include <stdio.h>
#define MOD 1000000007

int main(){
	long a,b,x;
	scanf("%ld%ld%ld",&a,&b,&x);
	printf("%ld\n",(x+(x-b>0)*(x-b)/(a-b)%MOD*(b%MOD))%MOD);
}


Measured memory_bytes: 2148
N, A, B, C, D = map(int,input().split())
S = input()

for k in range(A-1,C-1):
    if S[k] == S[k+1] == "#":
        print("No")
        exit(0)
for k in range(B-1,D-1):
    if S[k] == S[k+1] == "#":
        print("No")
        exit(0)

if C < D:
    print("Yes")
    exit(0)
for k in range(B-2,D-1):
    if S[k] == S[k+1] == S[k+2] == ".":
        print("Yes")
        exit(0)
print("No")
exit(0)


Measured memory_bytes: 3572
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cstdio>
#include <cstdlib>

using namespace std;

int main()
{
    int N, Z, W;
    if (scanf("%d%d%d", &N, &Z, &W) < 3) return 0;

    int a;
    int bka = W;
    for (int i = 0; i < N; i++)
    {
        if (scanf("%d", &a) < 1) return 0;
        if (i != N - 1) bka = a;
    }

    printf("%d\n", max(abs(a - W), abs(a - bka)));
    return 0;
}


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

int main(){
    vector<int>v{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int a;
    cin >>a;
    a--;
    cout <<v.at(a);
}

Measured memory_bytes: 256
N = input()
n = [int(i) for i in N]
N = int(N)
a = n[0]
b = len(n)
c = 0

for i in range(b):
    c += a*10**i

if N <= c:
    print(c)
else:
    c = [str(int(i)+1) for i in str(c)]
    print(''.join(c))


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

signed main() {
  int n,m;
  cin >> n >> m;

  int answer = 1;
  for (int i = 1; i * i <= m; i++) {
    if(m % i == 0) {
      int d1 = i;
      int d2 = m/i;
      if(n <= m/d1) answer = max(answer, d1);
      if(n <= m/d2) answer = max(answer, d2);
    }
  }
  cout << answer << endl;

  return 0;
}

Measured memory_bytes: 3552
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
  int q;
  cin >> q;
  rep(i, q){
    string a, b;
    cin >> a >> b;
    vector<vector<int>> dp(b.size()+1, vector<int>(a.size()+1));
    rep(i, b.size()+1){
      rep(j, a.size()+1){
        if(i == 0 || j == 0){
          dp.at(i).at(j) = 0;
          continue;
        }
        if(a.at(j-1) == b.at(i-1)) dp.at(i).at(j) = dp.at(i-1).at(j-1) + 1;
        else dp.at(i).at(j) = max(dp.at(i-1).at(j), dp.at(i).at(j-1));
      }
    }
    cout << dp.at(b.size()).at(a.size()) << endl;
  }
  return 0;
}


Measured memory_bytes: 6852
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int x, y;
  char input[150];
  fgets(input, 149, stdin);
  sscanf(input, "%d %d", &x, &y);

  /*int preTsuru, preCameFeet, camex, tsuru;
  preTsuru = x * 2;
  preCameFeet = y - preTsuru;
  if (preCameFeet % 2 != 0 || y % 2 != 0) {
    printf("No\n");
    return 0;
  }
  camex = preCameFeet / 2;
  tsuru = x - camex;
  if (camex < 1 || camex > 100 || tsuru < 1 || tsuru > 100) {
    printf("No\n");
    return 0;
  } else if (camex + tsuru == x) {
    printf("Yes\n");
  } */

  for (size_t i = 0; i < x+1; i++) {
    int a;
    a = x - i;
    if (a * 2 + i * 4 == y) {
      printf("Yes");
      return 0;
    }
  }
  printf("No");

  return 0;
}


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

const int INF = 1e9;
const int MOD = 1e9 + 7;

using namespace std;

typedef long long ll;

#define REP(i, n) for (int i = 0; i < int(n); i++)
#define REPD(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = a; i < int(b); i++)
#define FORD(i, a, b) for (int i = b - 1; i >= int(a); i--)
#define WRAP(y, x, h, w) (0 <= y && y < h && 0 <= x && x < w)

#define ALL(x) (x).begin(), (x).end()

int gcd(int a, int b)
{
    return b ? gcd(b, a % b) : a;
}
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };

int main()
{
    int N, X, T;
    cin >> N >> X >> T;
    int ans = 0;
    while (N > 0) {
        ans += T;
        N -= X;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3616
import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  import MapHelper._
  val n = in.readInt
  val seq = in.readLine.split(" ").map(_.toInt)

  val map1 = mu.HashMap.empty[Int,Int]
  val map2 = mu.HashMap.empty[Int,Int]
  for(i <- 0 until n) {
    if(i % 2 == 0) map1.addOrUpdate(seq(i), 1)
    else map2.addOrUpdate(seq(i), 1)
  }

  val max1 = map1.toIndexedSeq.sortBy(_._2)(Ordering[Int].reverse).take(2)
  val max2 = map2.toIndexedSeq.sortBy(_._2)(Ordering[Int].reverse).take(2)
  // println(max1.mkString(" "))
  // println(max2.mkString(" "))

  val res = (max1, max2) match {
    case (a, b) if a.head._1 != b.head._1 => a.head._2 + b.head._2
    case (a, b) if a.size == 2 && b.size == 2 => (a.head._2 + b.last._2) max (a.last._2 + b.head._2)
    case (a, b) if b.size == 2 => a.head._2 + b.last._2
    case (a, b) if a.size == 2 => a.last._2 + b.head._2
    case _ => n / 2
  }

  val ans = n - res
  println(ans)

  object MapHelper {
    implicit class AddOrUpdate[A](map:mu.HashMap[Int,Int]) {
      def addOrUpdate(key:Int, value:Int):mu.HashMap[Int,Int] =
      {
        if(map.contains(key)) map(key) += value
        else map += (key -> value)
        map
      }
    }
  }
}

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

 
public class Main {
 
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int n  = sc.nextInt();
		List<List<Integer>> permutation = new ArrayList<>();
        List<Integer> candidate = new ArrayList<>(n);
		StringBuffer P = new StringBuffer();
		StringBuffer Q = new StringBuffer();
		
		for(int i = 1; i <= n; i++) {
			candidate.add(i);
		}
		for(int i = 1; i <= n; i++) {
			P.append(sc.nextInt());
		}
		for(int i = 1; i <= n; i++) {
			Q.append(sc.nextInt());
		}
		
		List<List<Integer>> result = new ArrayList<>();
        List<Integer> perm = new ArrayList<>();
        permutation = buildPerm(result, candidate, perm);
        int pNum = 0;
        int qNum = 0;
        
        for(int i = 0; i < permutation.size(); i++) {
        	StringBuffer num = new StringBuffer();
        	for(int temp : permutation.get(i)) {
        		num.append(temp);
        	}
        	if(num.toString().equals(P.toString())) {
        		pNum = i + 1;
        	}
        	if(num.toString().equals(Q.toString())) {
        		qNum = i + 1;
        	}
        }
        
		System.out.println(Math.abs(pNum - qNum));
		sc.close();
	}
	
    private static List<List<Integer>> buildPerm(List<List<Integer>> result, List<Integer> candidate, List<Integer> perm) {
        if (candidate.size() == 0) {
            result.add(perm);
        }
        else {
            for (int i = 0; i < candidate.size(); i++) {
                List<Integer> p = new ArrayList<>(perm);
                List<Integer> c = new ArrayList<>(candidate);
                p.add(c.get(i));
                c.remove(i);
                buildPerm(result, c, p);
            }
        }

        return result;
    }
	
}

Measured memory_bytes: 59448
n, a, b = map(int, input().split())
mod = int(1e9 + 7)
# print(1e9+7)

def comb(r):
    bunshi = 1
    # iは2からnの範囲を動く
    for i in range(n - r + 1, n + 1):
        bunshi = bunshi * i % mod
    bunbo = 1
    for i in range(1, r + 1):
        bunbo = bunbo * i % mod
    return bunshi * pow(bunbo, mod - 2, mod) % mod


ans = pow(2, n, mod) - 1 - comb(b) - comb(a)
ans = (ans + 2 * mod) % mod
ans1 = ans% mod
print(ans1)

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

int main(void){
    char a,t;
    cin >> a >> t;
    if(a == 'H'){
        if(t == 'H')cout << "H";
        else cout << "D";
    } else {
        if(t == 'H')cout << "D";
        else cout << "H";
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
#include <numeric>
using namespace std;
using Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)


int H, W, K;
int X1, Y1, X2, Y2;
vector<vector<int>>v;
vector<vector<int>>dist;
vector<set<int>>stx, sty;


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

	cin >> H >> W >> K >> X1 >> Y1 >> X2 >> Y2;
	X1--; Y1--; X2--; Y2--;
	v.resize(H);
	dist.resize(H);
	stx.resize(H);
	sty.resize(W);

	for (int i = 0; i < H; i++) {
		v[i].resize(W);
		dist[i].resize(W);
		for (int j = 0; j < W; j++) {
			char c;
			cin >> c;
			v[i][j] = (c == '@');
			dist[i][j] = 1e9;
		}
	}

	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++)stx[i].insert(j);
		stx[i].insert(2e9);
		stx[i].insert(-2e9);
	}
	for (int j = 0; j < W; j++) {
		for (int i = 0; i < H; i++)sty[j].insert(i);
		sty[j].insert(2e9);
		sty[j].insert(-2e9);
	}
	

	queue<pair<int, int>>q;
	q.push({X1,Y1});
	stx[X1].erase(Y1);
	sty[Y1].erase(X1);
	dist[X1][Y1] = 0;
	while (q.size()) {
		auto p = q.front();
		q.pop();
		int curx = p.first;
		int cury = p.second;
		int curd = dist[curx][cury];
		int X, Y;
		//右
		Y = cury;
		while (Y < W) {
			auto itr = stx[curx].upper_bound(Y);
			int nxtY = *itr;
			if (abs(nxtY - cury) > K)break;
			if (v[curx][nxtY] == 1)break;
			dist[curx][nxtY] = curd + 1;
			stx[curx].erase(nxtY);
			sty[nxtY].erase(curx);
			q.push({curx,nxtY});
			Y = nxtY;
		}
		//左
		Y = cury;
		while (0 <= Y) {
			auto itr = stx[curx].lower_bound(Y);
			itr--;
			int nxtY = *itr;
			if (abs(nxtY - cury) > K)break;
			if (v[curx][nxtY] == 1)break;
			dist[curx][nxtY] = curd + 1;
			stx[curx].erase(nxtY);
			sty[nxtY].erase(curx);
			q.push({ curx,nxtY });
			Y = nxtY;
		}
		//下
		X = curx;
		while (X < H) {
			auto itr = sty[cury].upper_bound(X);
			int nxtX = *itr;
			if (abs(nxtX - curx) > K)break;
			if (v[nxtX][cury] == 1)break;
			dist[nxtX][cury] = curd + 1;
			stx[nxtX].erase(cury);
			sty[cury].erase(nxtX);
			q.push({nxtX,cury});
			X = nxtX;
		}
		//上
		X = curx;
		while (0 <= X) {
			auto itr = sty[cury].lower_bound(X);
			itr--;
			int nxtX = *itr;
			if (abs(nxtX - curx) > K)break;
			if (v[nxtX][cury] == 1)break;
			dist[nxtX][cury] = curd + 1;
			stx[nxtX].erase(cury);
			sty[cury].erase(nxtX);
			q.push({ nxtX,cury });
			X = nxtX;
		}
	}

	if (dist[X2][Y2] > 1e8)puts(-1);
	else puts(dist[X2][Y2]);

	
	return 0;
}

Measured memory_bytes: 245536
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
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; }

int main(){
  int n; cin >> n;
  string s; cin >> s;
  vi txt(n);
  rep(i,n){
    if(s[i] == 'R') txt[i] = 0;
    if(s[i] == 'G') txt[i] = 1;
    if(s[i] == 'B') txt[i] = 2;
  }
  vi rgb(3);
  rep(i,n) rgb[txt[i]]++;
  ll ans = 1;
  rep(i,3) ans *= rgb[i];
  rep(j,n){
    rep(i,j){
      if(2*j-i < n && txt[i] != txt[j] && txt[j] != txt[2*j-i] && txt[2*j-i] != txt[i]) ans--;
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}


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

int main()
{
	string strInput;
	int nCount, nTemp;
	while (cin >> strInput, "-" != strInput)
	{
		cin >> nCount;
		for (int i = 0; i < nCount; i++)
		{
			cin >> nTemp;
			strInput = strInput.substr(nTemp) + strInput.substr(0, nTemp);
		}
		cout << strInput << endl;
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <complex>
#define repi(i, x, n) for(int i = x; i < n; i++)
#define rep(i, n) repi(i, 0, n)
#define endl "\n"
#define ing long long
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

#define w first
#define t second
#define c first
#define d second

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

    int M, N;
    vector<pair<int,int>> in, cd;
    vector<int> dp, sum1, sum2;

    cin>>M>>N;

    in.resize(M);
    sum1.resize(M+1,0);
    sum2.resize(M+1,0);
    cd.resize(N);
    dp.resize((1<<N) + 10);
    
    for(int i = 0; i < M; i++){
        cin>>in[i].w>>in[i].t;
        sum1[i+1] += in[i].w;
        sum2[i+1] += in[i].t;
        sum1[i+1] += sum1[i];
        sum2[i+1] += sum2[i];
        // cout<<"i = "<<i+1<<" sum1 "<<sum1[i+1]<<endl;
        // 
        // cout<<"i = "<<i+1<<" sum2 "<<sum2[i+1]<<endl;
    }

    for(int i = 0; i < N; i++){
        cin>>cd[i].c>>cd[i].d;
    }

    dp[0] = -1;

    for(int i = 1; i < (1<<N); i++){
        int maximum = -1 ;
        for(int j = 0; j < N; j++){
            int bit = i&(~(1<<j));
            
            //cout<<"bit = "<<bit<<" "<<i<<endl;
            if(bit == i) continue;
            int num = dp[bit];
            int W = 0, T = 0;
            maximum = max(num, maximum);
            int x = 0,  y = 0;

            if(num == M-1){
                cout<<M<<endl;
                return 0;
            }
            //if(num != -1)
                x = sum1[num+1] +cd[j].c;
                //if(num != -1)
                y = sum2[num+1]+ cd[j].d;
            
            /*
            for(int k = num+1; k < M; k++){
                W += in[k].w;
                T += in[k].t;
                if(W > cd[j].c || T > cd[j].d) break;

                maximum = max(k,maximum);
            }

            */
            int temp1 = upper_bound(sum1.begin(), sum1.end(), x) - sum1.begin();
            int temp2 = upper_bound(sum2.begin(), sum2.end(), y) - sum2.begin();
            // cout<<i<<" "<<j<<" "<<temp1<<" "<<temp2<<endl;
            // cout<<"x = "<<x<<" y = "<<y<<" num = "<<num<<" temp = "<<min(temp1,temp2)-1<<endl;
            maximum = max(min(temp1,temp2)-2, maximum);
            
        }
        dp[i] = maximum;
        //cout<<i<<" "<<maximum<<endl;
    }

    cout<<dp[(1<<N)-1]+1<<endl;
    
    return 0;
}




Measured memory_bytes: 5872
#include <stdio.h>

int main(void) {

  char buf[20];
  char c;

  int i;

  
  while(fgets(buf,sizeof(buf),stdin)!=NULL) {

    if((buf[0]=='o' && buf[1]=='o' && buf[2]=='o') || (buf[3]=='o' && buf[4]=='o' && buf[5]=='o') || (buf[6]=='o' && buf[7]=='o' && buf[8]=='o') || (buf[0]=='o' && buf[3]=='o' && buf[6]=='o') || (buf[1]=='o' && buf[4]=='o' && buf[7]=='o') || (buf[2]=='o' && buf[5]=='o' && buf[8]=='o') || (buf[0]=='o' && buf[4]=='o' && buf[8]=='o') || (buf[2]=='o' && buf[4]=='o' && buf[6]=='o')) printf("o\n");

    else if((buf[0]=='x' && buf[1]=='x' && buf[2]=='x') || (buf[3]=='x' && buf[4]=='x' && buf[5]=='x') || (buf[6]=='x' && buf[7]=='x' && buf[8]=='x') || (buf[0]=='x' && buf[3]=='x' && buf[6]=='x') || (buf[1]=='x' && buf[4]=='x' && buf[7]=='x') || (buf[2]=='x' && buf[5]=='x' && buf[8]=='x') || (buf[0]=='x' && buf[4]=='x' && buf[8]=='x') || (buf[2]=='x' && buf[4]=='x' && buf[6]=='x')) printf("x\n");
  
    else printf("d\n");

  }

  return 0;

}

Measured memory_bytes: 0
//Acknowledgement:  Xiaoyu Han, for his "brute-force" proposal

#include <cstdio>
#include <algorithm>
#include <cstdlib>

using std::max;  using std::abs;
using std::min;

const int MAXN=105;

int N,cx,cy,ch=0,c_point,min_abs;                     //c_point: calculable point
int x[MAXN],y[MAXN],h[MAXN];

int main()
{
    scanf("%d",&N);
    for (int i=1;i<=N;++i)
        scanf("%d%d%d",&x[i],&y[i],&h[i]);
    for (cx=0;cx<=100&&ch<=0;++cx)
    {
        for (cy=0;cy<=100&&ch<=0;++cy)
        {
            min_abs=MAXN<<1;
            for (c_point=1;c_point<=N&&h[c_point]==0;++c_point);
            ch=h[c_point]+abs(x[c_point]-cx)+abs(y[c_point]-cy);
            int i;
            for (i=1;i<=N&&h[i]==max(ch-abs(x[i]-cx)-abs(y[i]-cy),0);++i);
            if (i<=N) ch=0;
        }
    }
    printf("%d %d %d",--cx,--cy,ch);

    return 0;
}


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

long long mySolution(long long num){
	long long min_step = num;
	for(long long i=1; i<=sqrt(num); i++){
		if(num%i==0){
			long long d = num/i;
			long long cur_step = d-1+i-1;
			min_step = min(min_step, cur_step);
		}
	}
	return min_step;
}
int main(){
	long long n;
	cin >> n;
	cout << mySolution(n) << endl;
    return 0;
}

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

int main() {
  int N; cin >> N;
  vector<pair<int, int>> AB(N);
  for (int i = 0; i < N; i++) cin >> AB[i].second >> AB[i].first;
  
  sort(AB.begin(),AB.end());
  reverse(AB.begin(),AB.end());
  
  int t = AB[0].first;
  
  for (int i = 0; i < N; i++) {
    t = min(AB[i].first,t);
    t -= AB[i].second;
  }
  
  if (t < 0) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 1792
/*
god taekyu
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

int n,m;
vector<int> graph[100005];
int dp[100005];
int vt[100005];
int dfs(int idx) {
    if(vt[idx]) return dp[idx];
    vt[idx] = 1;
    int ret = 1;
    for(int j=0;j<graph[idx].size();j++) {
        int tmp = dfs(graph[idx][j]);
        ret = max(ret, tmp + 1);
    }
    return dp[idx] = ret;
}
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>m;
    for(int i=0;i<m;i++) {
        int a,b;
        cin>>a>>b;
        graph[a].push_back(b);
    }
    int ans = 1;
    for(int i=1;i<=n;i++) {
        ans = max(ans, dfs(i));
    }
    cout<<ans-1;
    return 0;
}

/*
god taekyu
*/


Measured memory_bytes: 8576
#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#include <functional>
//#include <numeric>
#pragma warning(disable:4996) 
 
typedef long long ll;
typedef unsigned long long ull;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;


void solve()
{
    int n; ll K;
    scanf("%d%lld", &n, &K);
    vector<vector<int> > a(n);
    int i, j;
    for (i = 0; i < n; i++) {
        int tmp;
        scanf("%d", &tmp); tmp--;
        a[i].push_back(tmp);
    }

    for (i = 1; i < 70; i++) {
        for (j = 0; j < n; j++) {
            a[j].push_back(a[a[j][i-1]][i - 1]);
        }
    }

    int curr = 0;
    int cnt=0;
    while(K>0) {
        if(K & ((ll)1<<cnt)) {
            curr = a[curr][cnt];
            K -= ((ll)1<<cnt);
        }
        cnt++;
    }
    printf("%d\n", curr + 1);

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


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


num, num2,num3 = 1, 1, 1

for _ in range(N):
    num = num * 10 % 1000000007
    num2 = num2 * 9 % 1000000007
    num3 = num3 * 8 % 1000000007
print((num - num2 * 2 + num3) % 1000000007)


Measured memory_bytes: 9160
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(long long i=0;i<n;++i)
#define REPP(i,m,n) for(long long i=m;i<n;++i)
#define rep(i,n) for(long long i = n-1;i>=0;--i)
#define repp(i,n,m) for(long long i = n-1; i >= m; --i)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
#define pq priority_queue
#define Dcout(N) cout << setprecision(20) << N << endl
constexpr int MOD = 1000000007;
constexpr int INF = 2147483647;
constexpr long long INFF = 9223372036854775807;

signed main() {
    cin.tie(0);
	ios::sync_with_stdio(false);
    ll H;cin >> H;
    ll sum = 1,ans = 1;
    REP(i,1000000000){
        if(H < sum){
            cout << sum-1 << endl;
            return 0;
        }
        sum *= 2;
        ans += sum;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
    int N;
    int S;
    char str[10001]={};

    scanf("%d\n",&N);
    scanf("%s\n",str);
    
    S=strlen(str);
    //printf("%d\n",S);
    
    int i,j;
    for(i=0;i<S;i++){
        for(j=0;j<N;j++){
            str[i]++;
            if(str[i]>'Z'){
                str[i]=str[i]-26;
            }
        }
    }
    //printf("%d",i);
    
   printf("%s",str);
    
    return 0;
}

Measured memory_bytes: 128
n=int(input())
temp0=input().split( )
k=int(temp0[0])
T=[int(s) for s in temp0[1:]]

m=2**n
for i in range(m):
    temp=[0 for i in range(n)]
    j=i
    count=0
    while j>0:
        if j%2==1:
            temp[count]=1
        j//=2
        count+=1
    flag=True
    for t in T:
        if temp[t]==0:
            flag=False
    if flag:
        temp2=[]
        for k in range(n):
            if temp[k]==1:
                temp2.append(k)
        print(i,end="")
        if i!=0:
            print(":",end=" " )
            print(*temp2)
        else:
            print(":")



Measured memory_bytes: 6244
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int max_n=1005;
map<int,vector<string>> mp={
    {3,{"aa.","..b","..b"}},
    {4,{"aaef","bbef","ghcc","ghdd"}},
    {5,{"aabbf","ccg.f","ddgee","..hij","..hij"}},
    {6,{"aabbcc","ddeeff","ghi...","ghi...","...jkl","...jkl"}},
    {7,{"aabbcc.","ddee..h","ffgg..h","....ijk","....ijk","....lmn","....lmn"}}
};
int a[max_n][max_n];
int n;
int row[max_n],col[max_n];
bool ok=false;
void dfs(int now){
    if(ok)return;
    if(now==2*n+1){
        bool f=true;
        for(int i=1;i<=n;i++)if(row[i]!=3||col[i]!=3)f=false;
        if(f){
            ok=true;
            cout<<n<<endl;
            for(int i=1;i<=n;i++){
                string s;s.resize(n);
                for(int j=1;j<=n;j++){
                    if(a[i][j]==0)s[j-1]='.';
                    else s[j-1]=a[i][j]-1+'a';
                }
                cout<<s<<endl;
            }
            cout<<endl;
        }
        return;
    }
    if(now<=n){
        for(int i=1;i<=n;i++){
            for(int j=1;j<n;j++){
                if(a[i][j]==0&&a[i][j+1]==0&&row[i]<3&&col[j]<3&&col[j+1]<3){
                    a[i][j]=a[i][j+1]=now;
                    row[i]++,col[j]++,col[j+1]++;
                    dfs(now+1);
                    a[i][j]=a[i][j+1]=0;
                    row[i]--,col[j]--,col[j+1]--;
                }
            }
        }
    }
    else{
        for(int i=1;i<n;i++){
            for(int j=1;j<=n;j++){
                if(a[i][j]==0&&a[i+1][j]==0&&row[i]<3&&row[i+1]<3&&col[j]<3){
                    a[i][j]=a[i+1][j]=now;
                    row[i]++,row[i+1]++,col[j]++;
                    dfs(now+1);
                    a[i][j]=a[i+1][j]=0;
                    row[i]--,row[i+1]--,col[j]--;
                }
            }
        }
    }
}
char ans[max_n][max_n];
int main(){
    //for(n=4;n<=7;n++)ok=false,dfs(1);
    scanf("%d",&n);
    if(n==2)printf("-1\n");
    else if(n==3){
        vector<string> v=mp[3];
        for(auto s:v){
            printf("%s\n",s.c_str());
        }
    }
    else{
        int r=n%4,m=n/4;
        if(r)r+=4,m--;
        vector<string> v=mp[4];
        for(int k=0;k<m;k++){
            for(int i=0;i<4;i++){
                for(int j=0;j<4;j++){
                    ans[k*4+i][k*4+j]=v[i][j];
                }
            }
        }
        if(r){
            v=mp[r];
            for(int i=0;i<r;i++){
                for(int j=0;j<r;j++){
                    ans[m*4+i][m*4+j]=v[i][j];
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                if(ans[i][j])printf("%c",ans[i][j]);
                else printf(".");
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }

int main() {
  int n;
  cin >> n;
  double p[n];
  for (int i=0; i<n; ++i) {
    cin >> p[i];
  }
  double dp[n+5][n+5]; // dp[i][j] i番目までのコインを全て投げたとき表=j枚の時の確率
                   // はじめのiは0
  dp[0][0] = 1.0;
  for (int i=0; i<n; ++i) {
    for (int j=0; j<=i; ++j) {
      dp[i+1][j+1] += dp[i][j] * p[i];
      dp[i+1][j] += dp[i][j] * (1.0 - p[i]);      
    }
  }
  double ans = 0.0;
  for (int i= (n+1)/2; i<=n; ++i) {
    ans += dp[n][i];
  }
  printf("%.10lf\n", ans);
  return 0;
}


Measured memory_bytes: 70144
# -*- coding: utf-8 -*-
"""
Basic Modifications - Rotate
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_4_B&lang=jp

"""
_ = input()
A = [int(a) for a in input().split()]
for _ in range(int(input())):
    b, m, e = map(int, input().split())
    t = [0]*(e-b)
    for i in range(e-b):
        j = (i + (e-m)) % (e - b)
        t[j] = A[b+i]
    A = A[:b] + t + A[e:]
print(*A, sep=' ')




Measured memory_bytes: 5844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool is_prime(int x){
  if(x<=1) return false;
  for(int i=2; i*i<=x; i++){
    if(x%i==0) return false;
  }
  return true;
}
int main() {
  int x;
  cin >> x;
  int p = x;
  while(!is_prime(p)){
    p++;
  }
  cout << p << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#include <set>
#include <list>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	string s;
	cin >> s;
	int ans = 0;
	int len = s.size();
	for (int i = 0;i < (int)len/2;i++) {
		if (s[i] != s[len - 1 - i]) ans++;
	}
	cout << ans << endl;
	return 0;
}


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

vector<bool> primeVec(ll num)
{
	vector<bool> vec(num, true);
	vec[0] = false, vec[1] = false;

	for (ll i = 2; i < num; ++i)
	{
		if (vec[i])
		{
			for (int j = i * 2; j < num; j+=i)
				vec[j] = false;
		}
	}
	return vec;
}


int main(int argc, char **argv)
{
	constexpr int MAX = 110000;
	int q;
	cin >> q;
	vector<int> l(MAX), r(MAX);

	for (int i = 0; i < q; ++i)
		cin >> l[i] >> r[i];

	vector<bool> p_vec = primeVec(MAX);

	vector<int> p(MAX, 0);
	for (int i = 1; i < MAX; ++i)
	{
		if (i%2==0) continue;
		else if (p_vec[i] && p_vec[(i + 1)/2]) p[i] = 1;
	}

	vector<int> p_cum_sum(MAX+1, 0);
	for (int i = 0; i < MAX; ++i) p_cum_sum[i+1] = p_cum_sum[i] + p[i];

	for (int i = 0; i < q; ++i)
	{
		std::cout << p_cum_sum[r[i]+1] - p_cum_sum[l[i]] << std::endl;
	}
}
 


Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define fi first
#define se second
#define ll long long
//priority_queue<int, vector<int>, greater<int> > pq;
#define _CRT_SECURE_NO_DEPRECATE
const int N = 330030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const ll mod =  1e9+7;
using namespace std;

int main() {
    ios::sync_with_stdio(false);
ll a,b;
cin>>a>>b;
if(a<=0&&b>=0)
{

cout<<"Zero";
return 0;}
if(a>0&&b>0)
{
cout<<"Positive";
return 0;}
if(abs(a-b)%2==0)
cout<<"Negative";
else
cout<<"Positive";

}


Measured memory_bytes: 256
from collections import deque

N, M = [int(s) for s in input().split()]
edge = [[int(s) - 1 for s in input().split()] for _ in range(M)]
graph = [[] for _ in range(N)]

for i, j in edge:
    graph[i].append(j)
    graph[j].append(i)

group = [0] * N
group_num = 0
visited = [False] * N

group_nums = [0] * N

for i in range(N):
    if visited[i]:
        continue
    dq = deque([i])
    group[i] = group_num
    visited[i] = True
    group_nums[group_num] += 1
    while(dq):
        search_obj = dq.pop()
        for candidate_obj in graph[search_obj]:
            if not visited[candidate_obj]:
                group[candidate_obj] = group_num
                dq.appendleft(candidate_obj)
                visited[candidate_obj] = True
                group_nums[group_num] += 1
    group_num += 1

print(max(group_nums))

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

using namespace std;

int main() {
  int N; cin>>N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    B[i] = A[i];
  }

  sort(B.begin(), B.end());
  int m = B[N-1];
  int n = B[N-2];

  for (int i = 0; i < N; i++) {
    if (A[i] == m) {
      cout << n << endl;
    } else {
      cout << m << endl;
    }
  }

  return 0;
}


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

public class Main {
    public static void main(String[] args) {
        FastScanner scanner = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i< n; i++) arr[i] = scanner.nextInt();
        int[] b = new int[n];
        int sum = 0;
        for(int i = 0; i < n; i++) {
            b[i] = scanner.nextInt();
            sum += b[i];
        }
        int[] c = new int[n-1];
        for(int i = 0; i < n-1; i++) c[i] = scanner.nextInt();
        for(int i = 1; i < n; i++) {
            if (arr[i] == arr[i-1] + 1) sum += c[arr[i-1]-1];
        }
        out.println(sum);
        out.flush();
    }
    
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;
        
        public FastScanner(Reader in) {
            br = new BufferedReader(in);
        }
        
        public FastScanner() {
            this(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String readNextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

const int MAX_ARRAY = 100;
int X[MAX_ARRAY] = {};
int P = 0;
int Loop = 0, In = 0;
string input;

string ANS = "";

stack<int> ST;

void Brainfuck(string S) {
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '>') {
			if (Loop == 0) {
				if (P == MAX_ARRAY - 1) {
					ANS = "ErrorNo.1 : 配列外参照";
					return;
				}
				P++;
			}
		}
		else if (S[i] == '<') {
			if (Loop == 0) {
				if (P == 0) {
					ANS = "ErrorNo.1 : 配列外参照";
					return;
				}
				P--;
			}
		}
		else if (S[i] == '+') {
			if (Loop == 0) {
				X[P]++;
			}
		}
		else if (S[i] == '-') {
			if (Loop == 0) {
				X[P]--;
			}
		}
		else if (S[i] == '.') {
			if (Loop == 0) {
				ANS += (char)X[P];
			}
		}
		else if (S[i] == ',') {
			if (Loop == 0) {
				X[P] = (int)input[In];
				In++;
			}
		}
		else if (S[i] == '[') {
			if (Loop == 0) {
				if (X[P] == 0) {
					Loop++;
				}
				else {
					ST.push(i);
				}
			}
			else {
				Loop++;
			}
		}
		else if (S[i] == ']') {
			if (Loop == 0) {
				if (ST.empty()) {
					ANS = "ErrorNo.2 : ループが不適切";
					return;
				}
				else {
					if (X[P] == 0) {
						ST.pop();
					}
					else {
						i = ST.top() - 1;
						ST.pop();
					}
				}
			}
			else {
				Loop--;
			}
		}
		else if (S[i] == ' ' || S[i] == '\n') continue;
		else {
			cout << i << endl;
			ANS = "ErrorNo3 : コードが不適切";
			return;
		}
	}
}

int main() {
	string Prog = ",>,,<[->[->+>+<<]>>[-<<+>>]<<<]>>[->>[>]+<[-<]<]+>>[+++++++++[-<+++++++++>]<-.++++++++++++.++++++++++++++.<->>[-]]<<[+++++++++[->++++++++<]>--.+++++++++++++++++++++++++++++++++.<]";
	getline(cin, input);
	Brainfuck(Prog);
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

ll GCD(ll m,ll n){
	if(n == 0) return m;
	else return GCD(n,m % n);
}

ll LCM(ll m,ll n){
	ll g = GCD(m,n);
	return m / g * n;
}

int main(){
	int n;
	cin >> n;
	ll t[n];
	REP(i,n) cin >> t[i];
	ll ans = 1;
	REP(i,n) ans = LCM(ans, t[i]);
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define COUNT(i, n) for(int i = 1; i <= n; i ++)
#define ITER(c) __typeof((c).begin())
#define each(c, it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define ALL(c) c.begin(), c.end()
#define mp make_pair
#define pb push_back
#define MEMSET(v, h) memset((v), h, sizeof(v))
 
using namespace std; 

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;
const string L[2] = {"qwertasdfgzxcvb", "yuiophjklnm"};

int main(void){
    int res, cur;
    for(string s; cin >> s, s != "#"; cout << res << endl){
        res = 0;
        rep(i, s.size()){
            if(!i) cur = !!~L[0].find(s.at(i));
            if(~L[cur].find(s.at(i))) cur = !cur, res++;
        }
    }
 
    return 0;
}

Measured memory_bytes: 1192
def main():
    import sys
    M, N = map(int, sys.stdin.readline().split())
    mod = 10**9+7
    
    # a**b
    def calc(a,b, mod):
        if b==1:
            return a % mod
        if b %2==0:
            return calc(a**2%mod, b//2, mod) % mod
        elif b % 2==1:
            return a*calc(a, b-1, mod) % mod
            
    
    ans = calc(M, N, mod)
    print(ans)
    #確認
    #print(pow(M, N, mod))
    
if __name__=='__main__':
    main()


Measured memory_bytes: 5616