akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for (long long i = 0; i < (n); ++i)
#define repr(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(x) for (auto&& v : (x))
#define updatemax(t, v) ((t) = std::max((t), (v)))
#define updatemin(t, v) ((t) = std::min((t), (v)))

#include <vector>

class uftree {
  int n, groups;
  std::vector<int> parent, sizev;

 public:
  uftree(const int n) {
    this->n = this->groups = n;
    parent.resize(n);
    sizev.resize(n);
    for (int i = 0; i < n; i++) {
      parent[i] = i;
      sizev[i] = 1;
    }
  }
  int root(const int x) { return parent[x] == x ? x : parent[x] = root(parent[x]); }
  bool same(const int x, const int y) { return root(x) == root(y); }
  int size(const int x) { return sizev[root(x)]; }
  bool unite(const int x, const int y) {
    int gx = root(x), gy = root(y);
    if (gx == gy) return false;
    if (sizev[gx] > sizev[gy]) std::swap(gx, gy);
    parent[gx] = gy;
    sizev[gy] += sizev[gx];
    sizev[gx] = 0;
    groups--;
    return true;
  }
  int count() const { return groups; }
};

bool seen[200100];
int main() {
  ll n, m;
  cin >> n >> m;
  uftree t(n);
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    --a;
    --b;
    t.unite(a, b);
  }
  ll res = -1;
  rep(i, n) {
    ll root = t.root(i);
    if (seen[root]) continue;
    seen[root] = true;
    updatemax(res, (ll)t.size(root));
  }
  cout << res << endl;
}


Measured memory_bytes: 4992
#include <iostream>
#include <utility>
#include <stdint.h>

using namespace std;

bool CHOCO[10][1001] = {false};

int main()
{
  int H, W, K;
  cin >> H >> W >> K;

  for (int h=0; h<H; ++h) {
    for (int w=0; w<W; ++w) {
      char s;
      cin >> s;
      CHOCO[h][w] = s=='1';
    }
    CHOCO[h][W] = false;
  }

  int ans = H*W;

  for (int pattern = 0; pattern < 1<<9; ++pattern) {
    int h_cut = 0;

    int group[10];

    int p = pattern;
    for (int h=0; h<10; ++h) {
      group[h] = h_cut;
      if (p%2) {
	h_cut++;
      }
      p >>= 1;
    }

    int wchocos_now[10] = {0};
    int wchocos_next[10] = {0};
    bool cut = false;
    int w_cut = 0;

    bool ok = true;

    for (int w=0; ok && w<W; ++w) {
      if (cut) {
	w_cut++;
	for (int g=0; g<10; ++g)
	  wchocos_now[g] = 0;
      }
      cut = false;
      
      for (int h=0; h<H; ++h) {
	if (CHOCO[h][w])
	  wchocos_now[group[h]]++;
      }

      for (int g=0; ok && g<10; ++g) {
	if (wchocos_now[g] > K)
	  ok = false;
	wchocos_next[g] = wchocos_now[g];
      }

      if (!ok)
	break;

      for (int h=0; !cut && h<H; ++h) {
	if (CHOCO[h][w+1])
	  wchocos_next[group[h]]++;

	if (wchocos_next[group[h]]>K)
	  cut = true;
      }
    }
    if (ok)
      ans = min(ans, h_cut + w_cut);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
// 6/14 リアルタイム参加
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Graph = vector<vector<int>>;

int H, W, K;
int sh, sw, gh, gw;
vector<string> field;

// vector<vector<bool>> seen;
// vector<vector<ll>> dist;

const int dh[4] = {1, -1, 0, 0};
const int dw[4] = {0, 0, 1, -1};

int main() {
    cin >> H >> W >> K;
    cin >> sh >> sw >> gh >> gw;
    sh--;
    sw--;
    gh--;
    gw--;

    field.resize(H);
    rep(h, H) {
        cin >> field[h];
    }

    // memset(seen, 0, sizeof(seen));

    vector<vector<ll>> dist(H, vector<ll>(W, -1));  // 未訪問
    queue<P> que;

    dist[sh][sw] = 0;
    que.push({sh, sw});

    while (!que.empty()) {
        P p = que.front();
        que.pop();

        // pから辿れる場所を全部たどる。
        rep(i, 4) {
            int count = 0;

            for (int j = 1; j <= K; j++) {
                int nh = p.first + dh[i] * j;
                int nw = p.second + dw[i] * j;

                // 場外アウトしたり、ハスの場合はbreak。それ以上伸ばさない。
                if (nh < 0 || nh >= H || nw < 0 || nw >= W) break;
                if (field[nh][nw] == '@') break;

                // 移動先が探索済みの時もブレイク。
                if (dist[nh][nw] != -1) {
                    count += 1;

                    if (count > 100) break;
                    
                    continue;
                }

                dist[nh][nw] = dist[p.first][p.second] + 1;
                que.push({nh, nw});
            }
        }

    }

    // rep(h, H) {
    //     rep(w, W) {
    //         cout << dist[h][w] << " ";
    //     }
    //     cout << endl;
    // }

    cout << dist[gh][gw] << endl;
}

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

int main() {
    int N, K;
    cin>>N>>K;
    int h[N];
    for(int i=0;i<N;++i){
        cin>>h[i];
    }
    int DP[N];
    DP[0] = 0;
    DP[1] = abs(h[1]-h[0]);
    for(int i=2;i<N;++i){
        long tmp = 1e9;
        for(int j=1;j<=min(K, i);++j){
            if(tmp > DP[i-j] + abs(h[i] - h[i-j])) tmp = DP[i-j] + abs(h[i] - h[i-j]);
        }
        DP[i] = tmp;
    }
    cout<<DP[N-1]<<endl;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
 
public class Main {
    public static void main(String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        try {
            String str = reader.readLine();
	    String s[]=str.split(" ");
	    int i1=Integer.parseInt(s[0]);
	    int i2=Integer.parseInt(s[1]);
	    int ss=i1*i2;
            System.out.println(ss+" "+(i1*2+i2*2));
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}



Measured memory_bytes: 24372
#include <stdio.h>
#define MAX 11
int main(void) {
    char s[MAX], ans[MAX];
    int i, j=0, k;
    
    scanf("%s", s);
    
    for(i=0; s[i]!='\0'; i++) {
        if(s[i]=='B') {
            if(j>0)
                j--;
        }else {
            ans[j] = s[i];
            j++;
        }
    }
    
    for(k=0; k<j; k++)
        printf("%c", ans[k]);
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import sys
from fractions import gcd
from string import ascii_uppercase as ABC
#input = sys.stdin.readline
def inpl(): return list(map(int, input().split()))

from itertools import permutations
N, K, S = inpl()
if S < 10**9:
    ans = [S]*(K) + [S+1]*(N-K)
else:
    ans = [S]*(K) + [S-1]*(N-K)
print(*ans)

Measured memory_bytes: 71848
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

class book {
  std::string title, author, date;

public:
  book(const std::string& title,
       const std::string& author,
       const std::string& date): title(title), author(author), date(date) {}

  std::string get_title() const { return title; }

  bool matches(const std::string& q_title,
               const std::string& q_author,
               const std::string& q_date_from,
               const std::string& q_date_to) const {

    if (q_title != "*") {
      bool has = false;
      for (size_t i = 0; i + q_title.length() <= title.length(); ++i) {
        if (title.compare(i, q_title.length(), q_title) == 0) {
          has = true;
          break;
        }
      }
      if (!has) return false;
    }
    if (q_author != "*") {
      bool has = false;
      for (size_t i = 0; i + q_author.length() <= author.length(); ++i) {
        if (author.compare(i, q_author.length(), q_author) == 0) {
          has = true;
          break;
        }
      }
      if (!has) return false;
    }
    if (q_date_from != "*") {
      if (date < q_date_from) return false;
    }
    if (q_date_to != "*") {
      if (date > q_date_to) return false;
    }
    return true;
  }
};

int main() {
  size_t N;
  scanf("%zu", &N);

  std::vector<book> s;
  for (size_t i = 0; i < N; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string title = buf;
    scanf("%s", buf);
    std::string author = buf;
    scanf("%s", buf);
    std::string date = buf;
    s.emplace_back(title, author, date);
  }

  size_t Q;
  scanf("%zu", &Q);
  for (size_t i = 0; i < Q; ++i) {
    char buf[128];
    scanf("%s", buf);
    std::string title = buf;
    scanf("%s", buf);
    std::string author = buf;
    scanf("%s", buf);
    std::string date_from = buf;
    scanf("%s", buf);
    std::string date_to = buf;

    for (const auto& si: s)
      if (si.matches(title, author, date_from, date_to))
        printf("%s\n", si.get_title().c_str());

    if (i+1 < Q) puts("");
  }
}



Measured memory_bytes: 2836
N, L = map(int, input().split())
a = list(map(int, input().split()))

idx = -1
for i in range(N - 1):
  if a[i] + a[i + 1] >= L:
    idx = i
    break

if idx == -1:
  print("Impossible")
else:
  print("Possible")
  for i in range(idx):
    print(i + 1)
  for i in range(N - 1, idx, -1):
    print(i)

Measured memory_bytes: 19968
N = gets.to_i
ABS = N.times.map { gets.split.map(&:to_i) }

as = []
bs = []
ABS.each do |ab|
  a, b = ab
  as.push(a)
  bs.push(b)
end

def m(arr)
  sorted = arr.sort
  if arr.count % 2 == 1
    sorted[(arr.count + 1) / 2 - 1]
  else
    (sorted[arr.count / 2 - 1] + sorted[arr.count / 2 + 1 - 1]) / 2.0
  end
end

am = m(as)
bm = m(bs)

if N % 2 == 1
  puts (bm - am + 1).round
else
  puts ((bm - am) * 2 + 1).round
end


Measured memory_bytes: 36104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int w = scanner.nextInt();
			int a = scanner.nextInt();
			int b = scanner.nextInt();
			System.out.println(Math.max(0, Math.abs(a - b) - w));
		}
	}
}


Measured memory_bytes: 21844
//written by NewbieChd
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
using namespace std;

const int BUF = 1000000;
char buf[BUF], *p1, *p2;
inline char getChar() { return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, BUF, stdin), p1 == p2) ? EOF : *p1++; }
inline int read() {
    register int f = 0;
    char c;
    while (!isdigit(c = getChar())) {}
    do
        f = f * 10 + (c ^ 48);
    while (isdigit(c = getChar()));
    return f;
}

const int maxT = 20000003, inf = 0x3f3f3f3f;

int root;
struct SegmentTree {
    int lSon[maxT], rSon[maxT], minVal[maxT], tag[maxT], cntNode;
    #define mid ((l + r) >> 1)
    SegmentTree() { memset(minVal, 0x3f, sizeof minVal), memset(tag, 0x3f, sizeof tag); }
    inline void update(int k, int val) { minVal[k] = min(minVal[k], val), tag[k] = min(tag[k], val); }
    inline void pushdown(int k) {
        if (tag[k] < inf) {
            if (!lSon[k])
                lSon[k] = ++cntNode;
            if (!rSon[k])
                rSon[k] = ++cntNode;
            update(lSon[k], tag[k]), update(rSon[k], tag[k]), tag[k] = inf;
        }
    }
    void modify(int& k, int l, int r, int x, int y, int val) {
        if (!k)
            k = ++cntNode;
        if (x <= l && r <= y) {
            update(k, val);
            return ;
        }
        pushdown(k);
        if (x <= mid)
            modify(lSon[k], l, mid, x, y, val);
        if (mid < y)
            modify(rSon[k], mid + 1, r, x, y, val);
    }
    int query(int k, int l, int r, int x) {
        if (!k)
            return inf;
        if (l == r)
            return minVal[k];
        pushdown(k);
        if (x <= mid)
            return query(lSon[k], l, mid, x);
        else
            return query(rSon[k], mid + 1, r, x);
    }
}tree;

int main() {
    int n = read(), Q = read(), i, s, t, x, ans;
    for (i = 1; i <= n; ++i) {
        s = read(), t = read(), x = read();
        if (t - x > 0)
            tree.modify(root, 0, 1e9, max(0, s - x), t - x - 1, x);
    }
    for (i = 1; i <= Q; ++i)
        x = read(), ans = tree.query(1, 0, 1e9, x), printf("%d\n", ans < inf ? ans : -1);
    return 0;
}


Measured memory_bytes: 249088
def rev26(s):
    for i in range(len(s) - 1, 0, -1):
        if (s[i] > s[i - 1]):
            chars = sorted(s[i:])
            for j in range(len(chars)):
                if chars[j] > s[i - 1]:
                    return s[0:i - 1] + chars[j]

    return "-1"
    

s = input()

if len(s) == 26:
    print(rev26(s))

else:
    alphabets = "abcdefghijklmnopqrstuvwxyz"
    for i in range(len(s)):
        alphabets = alphabets.replace(s[i], "")

    print(s + alphabets[0])


Measured memory_bytes: 3064
#include<cmath>
#include<iostream>
#include<algorithm>
#include <string>
#include <stdexcept>
using namespace std; 
int main(){
  int a[3],b,c,d,e;
 	cin >>a[0]>>a[1]>>a[2];
 sort(a,a+3);
  cout << a[2]-a[0];
  	
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
#include <array>
using namespace std;

template <typename T>
class stack {
  private:
    T* array;
    int topI;
  public:
    stack(int n){
      array = new T[n];
      topI = 0;
    }
    ~stack(void){
      delete[] array;
    }
    void push(T value){
      array[topI++] = value;
    }
    void pop(void){
      if(topI>0)
        topI--;
    }
    T top(void){
      return array[topI-1];
    }
};

int main(){
  char str_buf[256];
  stack<int> data_stack(100);

  while (scanf("%s", str_buf) != EOF){
    if (str_buf[0] < '0' || str_buf[0] > '9'){
      auto op2 = data_stack.top();
      data_stack.pop();
      auto op1 = data_stack.top();
      data_stack.pop();
      switch(str_buf[0]){
        case '+':
          data_stack.push(op1+op2);
          break;
        case '-':
          data_stack.push(op1-op2);
          break;
        case '*':
          data_stack.push(op1*op2);
      }
    }
    else {
      auto op = atoi(str_buf);
      data_stack.push(op); 
    }
  }

  cout << data_stack.top() << endl;
  return 0;
}




Measured memory_bytes: 3160
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8
from numba.types import Omitted

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@njit((i8[:, :], ), cache=True)
def to_undirected(G):
    N = len(G)
    G = np.vstack((G, G))
    G[N:, 0] = G[:N, 1]
    G[N:, 1] = G[:N, 0]
    ind = G[:, 0].argsort()
    return G[ind]

@njit([(i8, i8[:, :], i8[:], i8), (i8, i8[:, :], i8[:], Omitted(1))],
      cache=True)
def euler_tour(N, G, ind, root=1):
    parent = np.zeros(1 + N, np.int64)
    tour = np.zeros(N + N, np.int64)
    st = np.empty(len(G) + 10, np.int64)
    p = 0

    def add(v):
        nonlocal p
        st[p] = v
        p += 1

    def pop():
        nonlocal p
        p -= 1
        return st[p]

    add(-root)
    add(root)
    n = 0
    while p:
        v = pop()
        tour[n] = v
        n += 1
        if v > 0:
            for i in range(ind[v - 1], ind[v]):
                w = G[i, 1]
                if w == parent[v]:
                    continue
                add(-w)
                add(w)
                parent[w] = v
    return tour, parent

@njit((i8, i8[:], i8[:, :]), cache=True)
def main(N, A, G):
    G = to_undirected(G)
    ind = np.searchsorted(G[:, 0], np.arange(N + 1), 'right')
    tour, parent = euler_tour(N, G, ind)
    INF = 1 << 60
    reverse = np.empty((N + 1, 2), np.int64)
    dp = np.full(N + 1, INF, np.int64)
    ans = np.empty(N + 1, np.int64)
    for v in tour:
        if v > 0:
            i = np.searchsorted(dp, A[v])
            reverse[v] = i, dp[i]
            dp[i] = A[v]
            ans[v] = np.searchsorted(dp, INF)
        else:
            v = -v
            i, x = reverse[v]
            dp[i] = x
    return ans[1:]

N = int(readline())
A = np.array([0] + readline().split(), np.int64)
G = np.array(read().split(), np.int64).reshape(-1, 2)

ans = main(N, A, G)
print('\n'.join(map(str, ans.tolist())))

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

typedef long long ll;
typedef unsigned int ui;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;

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

    int n, c;
    cin >> n >> c;
    vi v(n), w(n);
    vector<vll> dp(n + 1, vll(c + 1));
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
    }

    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j <= c; ++j) {
            dp[i][j] = max(dp[i - 1][j], j >= w[i - 1] ? 
                           dp[i - 1][j - w[i - 1]] + v[i - 1] : 0);
        }
    }
    cout << dp[n][c] << '\n';

    return 0;
}

Measured memory_bytes: 80256
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static String I = "IMPOSSIBLE";
	public static String B = "Bad";
	public static String G = "Good";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int n = ni();
		int a = n % 10;
		String s = "";
		if (a == 3) {
			s = "bon";
		} else if (a == 0 || a == 1 || a == 6 || a == 8) {
			s = "pon";
		} else {
			s = "hon";
		}
		out(s);

	}

	public static int count(String search, String text) {
		int nsearch = search.length();
		int ntext = text.length();
		int count = 0;

		for (int i = 0; i <= ntext - nsearch + 1; i++) {
			for (int j = i + nsearch - 1; j < ntext; j++) {
				if (search.equals(text.substring(i, j + 1))) {
					count++;
				}
			}
		}

		return count;
	}

	/*
	 * 以下メソッド集
	 */
	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static int max(int a, int b) {
		return Math.max(a, b);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static int min(int a, int b) {
		return Math.min(a, b);
	}

	static long min(long a, long b) {
		return Math.min(a, b);
	}
}


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

int main() {
  vector<int> numbers(3);
  for (int i = 0; i < 3; i++){
    cin >> numbers.at(i);
  }
  sort(numbers.begin(), numbers.end());
  cout << numbers.at(0) + numbers.at(1) + numbers.at(2) * 10 << endl;
  
  //cout << a + b + c << endl;
}

Measured memory_bytes: 256
object Main {

  import scala.io.StdIn

  def main(args: Array[String]): Unit = {
    StdIn.readLine
    println {
      StdIn
        .readLine
        .split(" ")
        .map(_.toInt)
        .groupBy(identity)
        .map { case (_, ns) => ns.length % 2 }
        .groupBy(identity)
        .map {
          case (0, ns) => ns.toList.length / 2 * 2
          case (1, ns) => ns.toList.length
        }
        .sum
    }
  }
}

Measured memory_bytes: 90324
import math
from functools import reduce
 
def gcd(*num):
    return reduce(math.gcd,num)
 
K = int(input())
sum = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            sum += gcd(i,j,k)
print(sum)

Measured memory_bytes: 74944
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

using namespace std;

const int mod = (int)1e9 + 7;
int main() {
	int n;
	cin >> n;

	vector<int> bits(61, 0);
	long long a;
	for (int i = 0; i < n; i++) {
		cin >> a;

		for (int j = 0; j <= 60; j++) {
			if ((a >> j) & 1) {
				bits[j]++;
			}
		}
	}

	long long ans = 0;
	long long pow2 = 1;
	for (int i = 0; i <= 60; i++) {
		long long tmp = 1LL * bits[i] * (n - bits[i]) % mod;
		tmp = tmp * pow2 % mod;
		ans += tmp;
		ans %= mod;

		pow2 = pow2 * 2LL % mod;
	}

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


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

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
		String s;
		String[] t;
		int[] n;
		int number;
		while((s=reader.readLine())!=null){
			t=s.split(" ");
			number=t.length;
			n=new int[number];
			for(int i=0;i<number;i++){
				n[i]=Integer.parseInt(t[i]);
			}
			Arrays.sort(n);
			for(int j=number-1;j>=0;j--){
				System.out.print(n[j]);
				if(j!=0){
					System.out.print(" ");
				}
			}
			System.out.println("");
		}
	}
}

Measured memory_bytes: 17032
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    ans = 0
    for i, a in enumerate(A, start=1):
        if i % 2 == 1 and a % 2 == 1:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61708
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod107 1000000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>
#define all(v) v.begin(), v.end()
#define PI acos(-1)
 
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;
}
const ll INF = 10010001010;
const int inf = 1000034000;
 
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
 
int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  int s = 0;
  for(int i = 0;i < N;i++){
    cin >> A[i];
    s = s ^ A[i];
  }
  for(int i = 0;i < N;i++){
    cout << (s ^ A[i]) <<" ";
  }
  cout << endl;
} 

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

using namespace std;

int main() {
        ios::sync_with_stdio(false);
        cin.tie(0);
        long long n;
        cin >> n;
        if (n == 2)
                return cout << 1, 0;
        set<long long> res({ n, n - 1 });
        for (long long d = 2; d * d <= n; d++) {
                if (n % d == 0) {
                        long long x = n;
                        while (x % d == 0) {
                                x /= d;
                        }
                        if (x % d == 1) {
                                res.insert(d);
                        }
                        x = n;
                        while (x % (n / d) == 0) {
                                x /= (n / d);
                        }
                        if (x % (n / d) == 1) {
                                res.insert(n / d);
                        }
                }
        }
        --n;
        for (long long d = 2; d * d <= n; d++) {
                if (n % d == 0) {
                        res.insert(d);
                        res.insert(n / d);
                }
        }
        cout << res.size() << endl;
        return 0;
}

Measured memory_bytes: 256
import math
a, b, C = map(int, input().split())
C = math.pi * C / 180
S = a * b * math.sin(C) / 2
c2 = a**2 + b**2 -2*a*b*math.cos(C)
c = math.sqrt(c2)
L = a + b + c
h = 2*S / a
print(S)
print(L)
print(h)


Measured memory_bytes: 5708
#include<bits/stdc++.h>
#define LL long long
#define MAXN 300005
#define INF (1<<25)
#define P int(1e9+7)
using namespace std;

int N;
string t;

int s[26][MAXN];

int main(){
	
	ios::sync_with_stdio(0);
	
	cin>>t;
	N = t.length();
	t = "$" + t;
	
	for(int i=1;i<=N;i++){
		
		for(int j=0;j<26;j++){
			s[j][i] = s[j][i-1];
		}
		s[t[i]-'a'][i]++;
	}

	for(int i=1;i<=N-1;i++){
		if(t[i]==t[i+1]){
			cout<<i<<" "<<i+1<<endl;
			return 0;
		}
		
		if(i+2<=N && t[i]==t[i+2]){
			cout<<i<<" "<<i+2<<endl;
			return 0;
		}
	}
	
	cout<<"-1 -1"<<endl;
	
	return 0;
}

Measured memory_bytes: 28140
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;



#define pdd pair<ld, ld>

void lineFromPoints(pdd P, pdd Q, ld &a,
                        ld &b, ld &c)
{
    a = Q.second - P.second;
    b = P.first - Q.first;
    c = a*(P.first)+ b*(P.second);
}


void perpendicularBisectorFromLine(pdd P, pdd Q,
                 ld &a, ld &b, ld &c)
{
    pdd mid_point = make_pair((P.first + Q.first)/2,
                            (P.second + Q.second)/2);

    c = -b*(mid_point.first) + a*(mid_point.second);

    ld temp = a;
    a = -b;
    b = temp;
}

pdd lineLineIntersection(ld a1, ld b1, ld c1,
                         ld a2, ld b2, ld c2)
{
    ld determinant = a1*b2 - a2*b1;
    if (determinant == 0)
    {
        return make_pair(FLT_MAX, FLT_MAX);
    }

    else
    {
        ld x = (b2*c1 - b1*c2)/determinant;
        ld y = (a1*c2 - a2*c1)/determinant;
        return make_pair(x, y);
    }
}

ld ans = (ld)(1e8);
int n;
pair<ld,ld> p[60];

ld dist( ld x1 , ld y1 , ld x2 , ld y2 ){
    return (x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
}

void fn( ld x , ld y ){
    ld maxR = 0.0L;
    for(int i=0; i<n; i++){
        maxR = max( maxR , dist( x , y , p[i].fi , p[i].se ) );
    }
    ans = min( ans , maxR );
    return;
}

void findCircumCenter(pdd P, pdd Q, pdd R)
{
    ld a, b, c;
    lineFromPoints(P, Q, a, b, c);

    ld e, f, g;
    lineFromPoints(Q, R, e, f, g);

    perpendicularBisectorFromLine(P, Q, a, b, c);
    perpendicularBisectorFromLine(Q, R, e, f, g);

    pdd circumcenter =
           lineLineIntersection(a, b, c, e, f, g);

    if (circumcenter.first == FLT_MAX &&
        circumcenter.second == FLT_MAX)
    {
        ///
    }

    else
    {

        fn(  circumcenter.fi , circumcenter.se );
    }
}

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> n;
    for(int i=0; i<n; i++) cin >> p[i].fi >> p[i].se;

    for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) for(int k=j+1; k<n; k++) findCircumCenter( p[i] , p[j] , p[k] );
    for(int i=0; i<n; i++) for(int j=i+1; j<n; j++) fn( (p[i].fi+p[j].fi)/2.0L , (p[i].se+p[j].se)/2.0L );

    cout << setprecision( 15 );
    cout << sqrt( ans );

    return 0;
}


Measured memory_bytes: 256
import sys
from collections import deque
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())
def array(n,val=0):
    return [val]*n
def matrix(row,columns,val):
    return [[val]*columns for _ in range(row)]

def solve():
    dx = x2-x1
    dy = y2-y1

    x3 = x2 - dy
    y3 = y2 + dx
    x4 = x1 - dy
    y4 = y1 + dx
    print(x3,y3,x4,y4)
    return

if __name__=='__main__':
    x1,y1,x2,y2 = IL()
    solve()

Measured memory_bytes: 9288
#include <iostream>
#include <vector>

int main()
{
  int n;
  std::cin >> n;
  std::vector<int> d_vec;
  d_vec.reserve(n);
  for(int i = 0; i < n; i++)
  {
    int d;
    std::cin >> d;
    d_vec.push_back(d);
  }
  
  int r = 0;
  int iteration = (n*(n-1))/2;
  int origin = 0;
  int target = 1;
  for(size_t i = 0; i < iteration; i++)
  {
    r += d_vec[origin]*d_vec[target];
    if(target == d_vec.size()-1)
    {
      if(origin == d_vec.size()-2)
      {
        std::cout << r << std::endl;
        // return -1;
      }
      else
      {
        origin ++;
        target = origin +1;
      }
    }
    else
    {
      target ++;
    }
  }
}

Measured memory_bytes: 256
from collections import deque

def answer():
    s = deque(input())
    q = int(input())
    rev = False
    for i in range(q):
        query = input().split()
        if int(query[0]) == 2:
            f, c = int(query[1]), query[2]
            if (not rev and f == 1) or (rev and f == 2):
                s.appendleft(c)
            else:
                s.append(c)
        else:
            rev = not rev
    if rev:
        s = list(s)
        s = s[::-1]
    print(''.join(s))
    return

answer()

Measured memory_bytes: 8436
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int n = s[0];
            int m = s[1];
            int k = s[2];
            if (k % n == 0 || k % m == 0)
            {
                WriteLine("Yes");
                return;
            }
            else
            {
                for (int i = 1; i <= n; i++)
                {
                    for (int j = 1; j <= m; j++)
                    {
                        int tmp = 0;
                        tmp += i * m;
                        tmp += j * n;
                        tmp -= 2 * (i * j);
                        if (tmp == k)
                        {
                            WriteLine("Yes");
                            return;
                        }
                    }
                }
            }
            WriteLine("No");
        }
    }
}

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

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

    int sum = 0;
    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        sum += (b - a + 1);
    }
    cout << sum << endl;
}


Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

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

    int res = INF;
    rep(i, N) {
        int c, t;
        cin >> c >> t;
        if (t <= T) {
            chmin(res, c);
        }
    }

    if (res == INF) cout << "TLE" << endl;
    else cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
package main

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

type Process struct {
	Name string
	Time int
}

func main() {
	var n, q int
	fmt.Scan(&n)
	fmt.Scan(&q)

	queue := make([]Process, n)
	s := bufio.NewScanner(os.Stdin)
	for i := 0; i < n; i++ {
		s.Scan()
		splits := strings.Split(s.Text(), " ")
		time, _ := strconv.Atoi(splits[1])
		queue[i] = Process{splits[0], time}
	}

	time := 0
	for ;len(queue) > 0; {
		process := queue[0]
		queue = queue[1:]

		if process.Time <= q {
			time += process.Time
			fmt.Print(process.Name)
			fmt.Print(" ")
			fmt.Println(time)
		} else {
			time += q
			process.Time -= q
			queue = append(queue, process)
		}
	}
}



Measured memory_bytes: 6712
{-
HOME- ITP1-ITP1_3-D
Discussion Solution Statistics Submit
 
Repetitive Processing - How Many Divisors?
Time Limit : 1 sec, Memory Limit : 65536 KB
?´???°?????°

???????????´??° a???b???c ??????????????????a ?????? b ?????§?????´??°????????????c

????´???°?????????????????????????±???????????????°????????????????????????????????????
Input

a???b???c

?????????????????????????????§??????????????????????????????
Output

?´???°?????°???????????????????????????????????????
Constraints

    1???a,b,c???10000

a???b

Sample Input

5 14 80

Sample Output

3

  -}
import Data.List.Split
main = do
  s <- getLine
  putStrLn $ show (aux s)

aux :: String -> Int
aux s = length $ filter (\x-> c `mod` x==0) [a..b]
  where
  [a,b,c] = map (\x -> read x :: Int)  (splitOn " " s)

Measured memory_bytes: 4148
#/usr/bin/env python

L, R = map(int, input().split())
MOD = 2019

if R-L >= MOD:
    print(0)
    exit()

ans = MOD 
tmp = 0 
for i in range(L, R+1):
    for j in range(i+1, R+1):
        tmp = ((i%MOD)*(j%MOD))%MOD
        if tmp <= ans:
            ans = tmp 
print(ans)


Measured memory_bytes: 9116
def mod_pow(m, n, mod):
    if n == 0:
        return 1
    if n == 1:
        return m % mod

    res = 1
    if n % 2 == 1:
        res = res * m

    return (res * (mod_pow((m * m) % mod, n // 2, mod)) % mod) % mod


mod = 10 ** 9 + 7
m, n = map(int, input().split())
print(mod_pow(m, n, mod))



Measured memory_bytes: 5604
l = list(input())
n = len(l)
cursor = n-1
while True:
    if cursor >= 5 and l[cursor] == "r" and l[cursor-1] == "e" and l[cursor-2] == "s" and l[cursor-3] == "a" and l[cursor-4] == "r" and l[cursor-5] == "e":
        cursor = cursor - 6
        continue
    if cursor >= 4 and l[cursor] == "e" and l[cursor-1] == "s" and l[cursor-2] == "a" and l[cursor-3] == "r" and l[cursor-4] == "e":
        cursor = cursor -5
        continue
    if cursor >= 6 and l[cursor] == "r" and l[cursor-1] == "e" and l[cursor-2] == "m" and l[cursor-3] == "a" and l[cursor-4] == "e" and l[cursor-5] == "r" and l[cursor-6] == "d":
        cursor -= 7
        continue
    if cursor >= 4 and l[cursor] == "m" and l[cursor-1] == "a" and l[cursor-2] == "e" and l[cursor-3] == "r" and l[cursor-4] == "d":
        cursor -= 5
        continue
    if cursor == -1:
        print("YES")
        break
    else:
        print("NO")
        break

Measured memory_bytes: 4084
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define SZ(x) ((int)(x).size())
int gcd(int a,int b){return b?gcd(b,a%b):a;}
const double pi=acos(-1);


int main() {
    int S, W;
    cin >> S >> W;
  if (S<=W)
    cout << "unsafe" << endl;
  else puts ("safe");
}


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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

/*{
  }*/

using vi = vector<int>;
using vvi = vector<vi>;
using P = pair<int,int>;

signed main() {
  int h, w, n;
  cin >> h >> w >> n;

  vi a(n);
  rep(i, 0, n) cin >> a[i];

  vvi ans(h, vi(w));
  int col = 1;
  int i = 0, j = 0;
  rep(y, 0, h){
    rep(x, 0, w){
      if(y%2) ans[y][x] = col;
      else ans[y][w-1-x] = col;

      j++;
      if(j == a[i]) { i++; j = 0; col++; }
    }
  }

  rep(i, 0, h) rep(j, 0, w) cout << ans[i][j] << " \n"[j==w-1];

  return 0;
}



Measured memory_bytes: 476
#include <stdio.h>
#include <algorithm>
using namespace std;
using ll = long long;

int main() {
	int N;
	scanf("%d", &N);
	ll A[N];
	for (int i = 0; i < N; i++) {
		scanf("%lld", &A[i]);
	}
	sort(A, A + N);
	ll c = A[N - 1];
	for (int i = N - 2; i > (N - 1) / 2; i--) {
		c += A[i] * 2;
	}
	if (N % 2) {
		c += A[N / 2];
	}

	printf("%lld\n", c);

	return 0;
}


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

int main() {
  int A,B;
  cin >> A >> B;
  int ans = 0;
  for(int i = A ; i < B + 1 ; i++){
    int a,b,c,d,e;
    a = i / 10000;
    b = (i - a * 10000) / 1000;
    c = (i - a * 10000 - b * 1000) / 100;
    d = (i - a * 10000 - b * 1000 - c * 100) / 10;
    e = i - a * 10000 - b * 1000 - c * 100 - d * 10;
    if(a == e && b == d){
      ans++;
//      cout << i << endl;
    }
  }
  cout << ans << endl;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// namespace mp = boost::multiprecision;
// using Bint = mp::cpp_int;
// using Real = mp::number<mp::cpp_dec_float<1024>>;

int main(){
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A.at(i);
    rep(i, N) cin >> B.at(i);
    rep(i, N) cin >> C.at(i);
    sort(all(A));
    sort(all(C));
    A.push_back(INF);
    C.push_back(INF);

    ll ans = 0;
    rep(i, N){
        int b = B.at(i);
        ll an = lower_bound(all(A), b) - A.begin();
        ll cn = C.end() - upper_bound(all(C), b) - 1;
        ans += an * cn;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1920
N = input().split()
N = int(N[0])
d={}
score = 0

for i in range(N):
  S = input()
  S = sorted(S)
  S = ''.join(S)
  
  if S in d:
    score += d[S]
    d[S] +=1
  else:
    d[S] = 1
    
print(score)

Measured memory_bytes: 17844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

int N;

bool query(int num) {
	cout << "? " << num << endl;
	cout.flush();

	char ch;

	cin >> ch;

	//if (num <= N && to_string(num) <= to_string(N)) ch = 'Y';
	//else if (num > N && to_string(num) > to_string(N)) ch = 'Y';
	//else ch = 'N';
	//cerr << ch << endl;

	return ch == 'Y';
}

signed main() {
	// cin >> N;

	int pow10[10];
	{
		int tmp = 1;
		rep(i, 10) {
			pow10[i] = tmp;
			tmp *= 10;
		}
	}

	int keta = 0;
	{
		int low = 0;
		int high = 10;
		int mid = (high + low) / 2;
		while (high - low > 1) {
			int num = 1;
			rep(i, mid) num *= 10;
			if (query(num)) {
				low = mid;
			} else {
				high = mid;
			}
			mid = (high + low) / 2;
		}
		keta = mid;
	}

	int state = 0;
	int tmp = 0;

	int cr = 0;
	for (int i = keta - 1; keta >= 0; keta--) {
		int low = 0;
		int high = 10;
		int mid = (high + low + 1) / 2;
		while (high - low > 1) {
			int num = mid;
			rep(j, keta) num *= 10;
			num += cr;
			num *= 10;

			if (!query(num)) {
				low = mid;
			} else {
				high = mid;
			}
			mid = (high + low) / 2;
		}

		if (mid != 0 && mid != 9) state = -1;
		else if (state == 0 && mid == 9) {
			tmp++;
		}

		rep(j, keta) mid *= 10;
		cr += mid;
	}

	cr++;

	if (state == 0) {
		cr = pow10[tmp + 1];
	}

	if (cr == 10) {
		if (query(9)) cr = 1;
	}

	cout << "! " << cr << endl;
	cout.flush();

    return 0;
}


Measured memory_bytes: 596
#include <bits/stdc++.h>
#ifdef HIRO
#define d(f_, ...) printf((f_), ##__VA_ARGS__)
#else
#define d(f_, ...)
#endif

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef queue<int> qi;
typedef queue< pair<int, int> > qp;
#define mp make_pair
#define pi 3.14159265358979323846
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
#define gt(T) greater<T>()
#define sum(v) accumulate(v.begin(), v.end(), 0)
#define uni(v) do{ \
  sort(v.begin(), v.end()); \
  decltype(v)::iterator result = unique(v.begin(), v.end()); \
  v.erase(result, v.end()); \
}while(0)
#define fi(init, n) for(int i = init; i < n; ++i)
#define fj(init, n) for(int j = init; j < n; ++j)
#define fk(init, n) for(int k = init; k < n; ++k)
#define zero(x) memset(x, 0, sizeof(x))
#define negative(x) memset(x, ~0, sizeof(x))
const ll MOD = 1e9 + 7;
const int INF = 1e9;
const int di[] = { 0, 1, 0, -1 };
const int dj[] = { 1, 0, -1, 0 };

template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}
template<typename T>
int finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) return 1;
	else return 0;
}
ll frac(ll n){
	if (n == 0) return 1;
	return (n * frac(n - 1)) % MOD;
}
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;
}

int main(int argc, char** argv) {
#ifdef HIRO
  string quiz(argv[1]);
  string id(argv[2]);
  string filename("input/" + quiz + "/" + id + ".txt");
  ifstream fin(filename);
  if (fin.peek() == ifstream::traits_type::eof()) {
    cout << "No input.";
    return 0;
  }
  ifstream cin(filename);
  std::cin.rdbuf(cin.rdbuf());
#endif
  ld ans = 0;
  ld n;
  cin >> n;
  // ll n, m;
  // cin >> n >> m;
  // ll n, m, k;
  // cin >> n >> m >> k;
  n /= 3;
  ans = n * n * n;
  cout << setprecision(9) << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b){
	if(a==0 || b == 0) return a+b;
	if(a < b) return gcd(b, a);
	return gcd(a%b, b);
}

int main() {
	string s, t;
	ll n, m;
	cin >> n >> m;
	cin >> s >> t;
	ll d = gcd(n, m);
	ll b = (n*m)/d;
	bool c = true;
	for(ll i=0; i<d; i++){
		if(s[(n*i)/d] != t[(m*i)/d]){
			c = false;
		}
	}
	if(c){
		cout <<  b << endl;
	}else{
		cout << -1 << endl;
	}
	return 0;
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EACH(i, c) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

int N;
vector<int> G[101010];
int dp[101010][2];

int rec(int n, int pre, int precol) {
  if (dp[n][precol]) return dp[n][precol];

  int res = 1;
  for (auto x : G[n]) {
    if (x != pre) {
      if (precol == 1) {
        res *= rec(x, n, 0) % MOD;
        res %= MOD;

      } else {
        res *= (rec(x, n, 1) + rec(x, n, 0)) % MOD;
        res %= MOD;
      }
    }
  }

  return dp[n][precol] = res;
}

signed main() {
  cin >> N;
  for (int i = 0; i < N - 1; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  cout << (rec(0, -1, 0) + rec(0, -1, 1)) % MOD << endl;
  return 0;
}


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

int main() {
    int N;
    cin>>N;
    vector<int> A(N);

    rep(i,N) {
        cin>>A[i];
    }

    int goal,ans=0;
    goal=A[0]; //現在のボタン

    rep(i,N) {
        ans++;

        if (goal==2) {
            cout<<ans<<endl;
            break;
        }
        else {
            goal=A[goal-1];
            
        }
    }

    if (goal != 2) {
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 3756
#include <cmath>
#include <string>
#include <vector>
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;


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

    int H, W;
    cin >> H >> W;
    vector<vector<char>> A(H, vector<char>(W));
    for (int i = 0; i < H; ++i)
        for (int j = 0; j < W; ++j)
            cin >> A[i][j];

    vector<int> right(H, 0), left(H, 0);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') {
                left[i] = j;
                break;
            }
        }
        for (int j = 0; j < W; ++j) {
            if (A[i][j] == '#') right[i] = j;
        }
    }

    for (int i = 0; i < H-1; ++i) {
        if (right[i] > left[i+1]) {
            cout << "Impossible" << endl;
            return 0;
        }
    }
    cout << "Possible" << endl;
    return 0;
}

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

const ll INF = 1e18;
const ll MOD = 1000000007;
const ll MX = 1000000000000000000;
const ll XX = 9223372036000000000;//最大値


#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define PB push_back


int main(){
    ll a;
    cin >> a;
    vector<ll> b(a);
    rep(i, a) cin >> b.at(i);
    sort(ALL(b));
    
    ll ans = 1;
    ll limit = XX;
    rep(i,a) {ans *= b.at(i);
        if (ans > MX || b.at(i) > limit) {
            ans = -1;
            break;
        }
        else if (ans == 0) break;
        limit = XX / ans;
    }
    cout  << ans << endl;
}

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

int main(){
  int n;
  cin >> n;
  vector<int>a(n);
  for(int i=0;i<n;i++)
    cin >> a.at(i);
  sort(a.begin(),a.end());
  cout << a.at(n-1)-a.at(0) << endl;
}

Measured memory_bytes: 3600