akhauriyash/Code-Regression huggingface dataset:
N,M = map(int,input().split())
S = []
for i in range(M) :
    B = list(map(int,input().split()))[1:]
    for i in range(len(B)) :
        B[i] -= 1
    S.append(B)
P = list(map(int,input().split()))

ans = 0

for bit in range((1 << N)) :
    A = []
    for k in range(N) :
        if bit & (1 << k) :
            A.append(k)
    #print(A)
    for i in range(M) :
        cnt = 0
        for j in range(len(S[i])) :
            if S[i][j] in A :
                cnt += 1
        if (cnt % 2) != P[i] :
            break
    else :
        ans += 1
print(ans)


Measured memory_bytes: 3188
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
    string S,T;
    cin >> S >> T;
    int ans = 0;
    for(int i = 0;i < 3; i++)
    {
        if(S[i] == T[i]) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
while True:
    a, b, c = input().split()
    a = int(a)
    c = int(c)
    if b == "?":
        break
    if b == "+":
        print(a + c)
    if b == "-":
        print(a - c)
    if b == "*":
        print(a * c)
    if b == "/":
        print(a // c)


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

int main() {
  ll n;cin>>n;
  n--;
  ll ans=n*(n+1)/2;
  cout<<ans<<endl;
}

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

int main() {
    int N;

    cin >> N;

    string n_str = to_string(N);

    int keta_wa = 0;


    for (int i = 0; i < n_str.size(); i++) {
        int m = n_str[i] - 48;

        keta_wa += m;
    }

    if (N % keta_wa == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    

    return 0;

}





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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;
using Pl = pair<ll, int>;


void Main() {
	int n, m;
	cin >> n >> m;
	
	vvi to(n);
	rep(i,m){
	    int a, b;
	    cin >> a >> b;
	    a--; b--;
	    to[a].pb(b);
	    to[b].pb(a);
	}
	
	vi ans(n, -1);
	// bfs
	// (parent, me)
    queue<P> que;
    que.push(P(-1, 0));
    while(!que.empty()){
        P p = que.front(); que.pop();
        int parent = p.fi;
        int me = p.se;
        if(ans[me] != -1) continue;
        ans[me] = parent;
        for(auto next : to[me]){
            que.push(P(me, next));
        }
    }
    
    rep(i, n) {
        if(i == 0) cout << "Yes" << endl;
        else cout << ans[i]+1 << endl;
    }
    return;
}

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


Measured memory_bytes: 13076
//INCLUDE
//------------------------------------------
#include <bits/stdc++.h>
//DEFINE
//------------------------------------------
#define ll long long
#define ld long double
#define ALLv(a)  (a).begin(),(a).end()
#define ALL(a,n)  (a),(a)+n
#define vi vector<long long>
#define vd vector<long double>
#define vs vector<string>
//CONST
//------------------------------------------
#define INF 1010000000000000017LL
#define MOD 1000000007LL
#define EPS 1e-12
#define PI 3.14159265358979323846
//REPEAT
//------------------------------------------
#define   FOR(i,m,n) for(ll (i)=(m);   (i)<(n);  (i)++)
#define   REP(i,n)   for(ll (i)=0;     (i)<(n);  (i)++)
#define  REPS(i,x)   for(ll (i)=1;     (i)<=(x); (i)++)
#define  RREP(i,x)   for(ll (i)=(x)-1; (i)>=0;   (i)--)
#define RREPS(i,x)   for(ll (i)=(x);   (i)> 0;   (i)--)
#define  WREP(i,in,j,jn) REP(i,in)REP(j,jn)
//-----------------------------------------
#define dcml(n) fixed<<setprecision(n)
using namespace std;
int main(void){
    ll a,b,c;cin>>a>>b>>c;
    if(a+b==c||a+c==b||a==b+c)cout<<"Yes";
    else cout<<"No";
    cout<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

int main() {
    string s;
    cin >> s;
    int n = s.size();
    vector<int> a(n + 1, 0);
    rep(i, n) {
        if(s[i] == '<') a[i + 1] = max(a[i + 1], a[i] + 1);
    }
    for(int i = n - 1; i >= 0; i--) {
        if(s[i] == '>') a[i] = max(a[i], a[i + 1] + 1); 
    }
    ll ans = 0;
    rep(i, a.size()) ans += a[i]; 

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 2820
import sys

import numpy as np

readline = sys.stdin.buffer.readline


def main():
    H, W = map(int, readline().split())
    N = int(readline())
    A = list(map(int, readline().split()))
    B = np.ones([H * W], dtype=np.int32)

    s = 0
    for i, a in enumerate(A):
        B[s:s + a] = i + 1
        s += a

    B = np.reshape(B, [H, W])
    for i in range(H):
        if i % 2 == 1:
            B[i, :] = B[i, :][::-1]
        print(*B[i, :])


main()


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

using namespace std;
#define FOR(i,n) for(int i = 0; i < n; i++)
#define sz(c) ((int)c.size())

using ll = long long;

#include <complex>

using C = complex<double>;

double dot(C a, C b) {
	return a.real() * b.real() + a.imag() * b.imag();
}

double cross(C a, C b) {
	return a.real() * b.imag() - a.imag() * b.real();
}

double SQ(double x) {
	return x * x;
}

double dist2(C a) {
	return dot(a, a);
}

double dist2(C sa, C sb, C p) {
	if (dot(sb - sa, p - sa) <= 0) return dist2(p - sa);
	if (dot(sa - sb, p - sb) <= 0) return dist2(p - sb);
	return SQ(cross(sb - sa, p - sa)) / dist2(sa - sb);
}

bool used[5010];
double d[5010];

int main() {
	int n, m, x, y; scanf("%d%d%d%d", &n, &m, &x, &y);
	vector<C> vc;
	vc.emplace_back(x, y);
	FOR(i, n) {
		int a, b; scanf("%d%d", &a, &b);
		vc.emplace_back(a, b);
	}

	used[0] = true;
	n++;
	FOR(i, n) {
		if (i == 0) continue;
		double dist = dist2(vc[i] - vc[0]);
		d[i] = dist;
	}

	double ans = 0;
	FOR(_, m) {
		int use = -1;
		double cost = 1e100;
		FOR(i, n) {
			if (used[i]) continue;
			if (cost > d[i]) {
				cost = d[i];
				use = i;
			}
		}

		int from = -1;
		double from_cost = 1e100;
		FOR(i, n) {
			if (!used[i]) continue;
			double aa = dist2(vc[i] - vc[use]);
			if (from_cost > aa) {
				from_cost = aa;
				from = i;
			}
		}
		ans += sqrt(from_cost);

		used[use] = true;
		FOR(i, n) {
			if (used[i]) continue;
			double aa = dist2(vc[from], vc[use], vc[i]);
			d[i] = min(d[i], aa);
		}
	}

	printf("%.15lf\n", ans);
}

Measured memory_bytes: 3372
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep_3(i, initial, n) for (int i = (int)(initial); i < (int)(n); ++i)
#define repeat(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int i = (int)(n); i > 0; i--)
#define rep_r_3(i, initial, n) for (int i = (int)(initial); i > (int)(n); i--)
#define repeat_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define variable
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;
const double EPS = numeric_limits<double>::epsilon();
const long long INF = (long long)1e18;
// 最大公約数
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }

int main() {
	int N;
	cin >> N;
	vector<ll> A(N, 0);
	map<ll, ll> m;

	repeat(i, N) {
		ll a;
		cin >> a;
		A[i] = a;
		m[a]++;
	}

	ll sum = 0;
	for(auto it: m) {
		sum += (it.second * (it.second - 1)) / 2;
	}

	repeat(i, N) {
		ll a = A[i];

		ll diff1 = m[a] * (m[a] - 1) / 2;

		m[a]--;

		ll diff2 = m[a] * (m[a] - 1) / 2;

		cout << (sum - diff1 + diff2) << endl;
		m[a]++;
	}

	return 0;
}


Measured memory_bytes: 11008
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

x, y, z = inpl_str()
print(z + ' ' + x + ' ' + y)

Measured memory_bytes: 4072
w = input()
wl = []
for i in range(len(w)):
    wl.append(w[i])

from collections import Counter
W = Counter(wl)

answer = 'Yes'
for i in range(len(w)):
    if W[w[i]]%2 != 0:
        answer = 'No'
        break
        
print(answer)

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

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

    while (1) {
        int flag = 0;
        for(int i = 2; i < x; i++) {
            if (x % i == 0) flag = 1;
        }
        if (flag == 0) break;

        x++;
    }

    cout << x << endl;

    return 0;
}

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

int prefix[405];
int arr[405];
int dp[405][405];

int psum(int s, int e){
    if(s==0) return prefix[e];
    return prefix[e]-prefix[s-1];
}

int f(int s, int e){
    if(s==e) return 0;//arr[s];
    
    int &ans =dp[s][e];
    if(ans!=-1) return ans;
    
    ans = LONG_MAX;
    for(int i=s;i<e;i++){
        ans = min(ans, f(s,i)+f(i+1,e)+psum(s,e));
    }
    //cout<<s<<" "<<e<<" "<<ans<<endl;
    return ans;
}


int32_t main() {
    memset(dp,-1,sizeof(dp));
	int n;
	cin>>n;

	cin>>arr[0];
	prefix[0]=arr[0];
	for(int i=1;i<n;i++){
	    cin>>arr[i];
	    prefix[i]=prefix[i-1]+arr[i];
	}
	cout<<f(0,n-1);
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

typedef long long ll;

int depth(int i, map<int, vector<int>> &child) {

  vector<int> childs = child[i];

  if( childs.empty() ) { return 0; }

  // それぞれの子のトーナメントの深さをもとめる。
  vector<int> dc; // depth of childs
  for(auto c: childs) {
    dc.push_back( depth(c, child) );
  }

  // 深さが浅い人と先に対戦する。
  sort(dc.begin(), dc.end());

  int res = 0;
  int cn = dc.size();           // number of child
  for(int k = 0; k < cn; k++) {
    res = max(res, dc[k] + cn - k);
  }

  return res;

}

 int main() {

   int N;
   cin >> N;

   // child[i] == (i に負けた人たち)
   map< int, vector<int>  > child;
   for(int i = 2; i <= N; i++ ) {
     int p;
     cin >> p;
     child[p].push_back(i);
   }

   cout << depth(1, child) << "\n";

   return 0;
 }


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


int main(){
  std::string S;
  std::cin>>S;
  
  bool check=false;
  
  int remnum=S.length()-9;
  
  for(int j=0;j<S.length()-remnum;j++){
    std::string temp1=S.substr(0,j);
    if(j==S.length()-remnum-1){
      if(temp1=="keyence") check=true;
      break;
    }
    else{
      std::string temp2=S.substr(j+S.length()-7);
      if(temp1+temp2=="keyence") check=true;
    }
  }
  
  if(S=="keyence")  std::cout<<"YES"<<std::endl;
  else if(check) std::cout<<"YES"<<std::endl;
  else std::cout<<"NO"<<std::endl;
  
  return 0;
  
}


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

#define MAX(x,y) ((x>y)?x:y)

int mabs(int x,int y){
	if(x>y)return x-y;
	else return y-x;
}
int t[205],a[205],b[205],c[205];
int dp[205][205];
int main(){
	int i,j,k,d,n,ans;
	
	scanf("%d%d",&d,&n);
	for(i=0;i<d;i++)scanf("%d",&t[i]);
	for(i=0;i<n;i++)scanf("%d%d%d",&a[i],&b[i],&c[i]);
	memset(dp,0,sizeof(dp));
	for(i=0;i<n;i++)for(j=0;j<n;j++)
		if(a[i]<=t[0] && t[0]<=b[i] && a[j]<=t[1] && t[1]<=b[j])
			dp[1][j]=MAX(dp[1][j],mabs(c[i],c[j]));
	for(i=2;i<d;i++){
		for(j=0;j<n;j++){
			if(t[i]<a[j] || b[j]<t[i])continue;
			for(k=0;k<n;k++)dp[i][j]=MAX(dp[i][j],dp[i-1][k]+mabs(c[k],c[j]));
		}
	}
	ans=0;
	for(j=0;j<n;j++)ans=MAX(ans,dp[d-1][j]);
	printf("%d\n",ans);
	
	return 0;
}

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

int cntExch;

void bubbleSort(int A[], int n){
  for(int i = 0; i < n - 1; i++){
    for(int j = n - 1; j > i; j--){
      if(A[j] < A[j-1]){
        swap(A[j], A[j-1]);
        cntExch++;
      }
    }
  }
}

/*
void bubbleSort(int A[], int n){
  bool flag = true;
  while(flag){
    flag = false;
    for(int j = n - 1; j >= 1; j--){
      if(A[j] < A[j-1]){
        swap(A[j], A[j-1]);
        flag = true;
        cntExch++;
      }
    }
  }
}
*/
int main(void){
  int n, A[100];

  cin >> n;
  for(int i = 0; i < n; i++) cin >> A[i];

  bubbleSort(A, n);

  for(int i = 0; i < n; i++){
    cout << A[i];
    if(i < n - 1) cout << " ";
  }
  cout << endl;
  cout << cntExch << endl;
  return 0;
}

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

using namespace std;

int W, H, x, y;
vector<string> map(20);

void Move(char c)
{
    if (c == 'U') {
        map[y][x] = '^';
        if (y - 1 >= 0 && map[y - 1][x] == '.') {
            swap(map[y][x], map[y - 1][x]);
            --y;
        }
    }
    else if (c == 'D') {
        map[y][x] = 'v';
        if (y + 1 < H && map[y + 1][x] == '.') {
            swap(map[y][x], map[y + 1][x]);
            ++y;
        }
    }
    else if (c == 'L') {
        map[y][x] = '<';
        if (x - 1 >= 0 && map[y][x - 1] == '.') {
            swap(map[y][x], map[y][x - 1]);
            --x;
        }
    }
    else if (c == 'R') {
        map[y][x] = '>';
        if (x + 1 < W && map[y][x + 1] == '.') {
            swap(map[y][x], map[y][x + 1]);
            ++x;
        }
    }
    else if (c == 'S') {
        int dx = 0, dy = 0;
        if (map[y][x] == '^')
            dy = -1;
        else if (map[y][x] == '>')
            dx = 1;
        else if (map[y][x] == 'v')
            dy = 1;
        else if (map[y][x] == '<')
            dx = -1;

        for (int i = 1; ; ++i) {
            if (x + i * dx < 0 || x + i * dx >= W ||
                y + i * dy < 0 || y + i * dy >= H)
                break;
            if (map[y + i * dy][x + i * dx] == '*') {
                map[y + i * dy][x + i * dx] = '.';
                break;
            }
            if (map[y + i * dy][x + i * dx] == '#')
                break;
        }
    }
}

int main()
{
    int T;

    cin >> T;
    while (T--) {
        cin >> H >> W;

        for (int i = 0; i < H; ++i)
            cin >> map[i];
        for (int i = 0; i < H; ++i)
            for (int j = 0; j < W; ++j)
                if (map[i][j] == '^' || map[i][j] == '>' ||
                    map[i][j] == 'v' || map[i][j] == '<')
                    x = j, y = i;

        string order;
        int num;

        cin >> num;
        cin >> order;

        for (int i = 0; i < num; ++i)
            Move(order[i]);

        // Output
        for (int i = 0; i < H; ++i)
            cout << map[i] << "\n";
        if (T != 0)
            cout << endl;
    }

    return 0;
}

Measured memory_bytes: 1204
fun main(args: Array<String>) {
    val n = readInt()
    val (d, x) = readIntList()
    val a = (1..n).map { readInt() }
    var sum = 0
    for (i in 0 until n) {
        sum += ((d - 1) / a[i]) + 1
    }
    println(sum + x)
}

fun printYesOrNo(flag: Boolean) {
    println(if (flag) "Yes" else "No")
}

fun readIntList(): List<Int> = readLine()!!.split(' ').map { it.toInt() }

fun readInt(): Int = readLine()!!.toInt()

fun err(print: Any) {
    System.err.println(print)
}

Measured memory_bytes: 36316
#include<stdio.h>

int main()
{
  int h,w,N,n,i,j = 1;
  int ans = 0;

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

  if(h > w){
    n = h;
  }
  else{
    n = w;
  }
  
  while(n*j < N){
    ans++;
    j++;
  }

  printf("%d\n",ans + 1);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Main m = new Main(sc);
        m.show(m.solve());
        sc.close();
    }
    
	//フィールド
    Scanner sc;
    int A;
    String op;
    int B;
    
    //入力
    Main(Scanner sc) {
        this.sc = sc;
        this.A = sc.nextInt();
        this.op = sc.next();
        this.B = sc.nextInt();
    }
    
    //解答処理
    private int solve() {
        int answer = 0;
        if (op.equals("+")) {
        	answer = A + B;
        } else {
        	answer = A - B;
        }
        
        return answer;
    }
    
    //出力
    public void show(int answer) {
        System.out.println(answer);
    }

}


Measured memory_bytes: 35556
#include <algorithm>
#include <iostream>
#include <set>
#include <map>
#include <math.h>
#include <vector>
 
#define MOD 1000000007
typedef long long ll;
 
using namespace std;


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

	ll n, ans = 0;

	cin >> n;
	vector<ll> v(n+1);

	for(int i=1; i<=n; i++) {
		cin >> v[i];
		if(i&1 && v[i]&1) ans++;
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    vector<int> G[n];
    int s, t;
    rep(i, m) {
        cin >> s >> t;
        s--;
        t--;
        G[s].emplace_back(t);
    }
    set<P> S;
    double dp[n];
    dp[n - 1] = 0;
    for (int cur = n - 2; cur >= 0; cur--) {
        int cnt = 0;
        vector<pair<double, P>> v;
        double ave = 0;
        for (int to : G[cur]) {
            ave += dp[to];
            v.emplace_back(dp[to], P(cur, to));
            cnt++;
        }
        dp[cur] = 1 + ave / cnt;
        sort(ALL(v));
        reverse(ALL(v));
        S.emplace(v[0].second);
    }
    double ans = dp[0];
    for (auto s : S) {
        for (int cur = n - 2; cur >= 0; cur--) {
            int cnt = 0;
            double ave = 0;
            for (int to : G[cur]) {
                if (s == P(cur, to)) continue;
                ave += dp[to];
                cnt++;
            }
            if (cnt == 0) break;
            dp[cur] = 1 + ave / cnt;
        }
        ans = min(ans, dp[0]);
    }
    printf("%.10lf\n", ans);
    return 0;
}

Measured memory_bytes: 5072
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;

int h,w,x;
char s[1000][1000];
bool visited [1000][1000];
pair<int,int> start,goal;
queue<pair<int,pair<int,int>>> q;
vector<pair<int,int>> ino;

int main(){
  int h,w;cin>>h>>w;
  string map[100];
  rep(i,h){
    cin>>map[i];
  }
  rep(i,w){
    bool e = true;
    rep(j,h){
      if(map[j][i]=='#'){
        e=false;
        break;
      }
    }
    if(e){
      rep(j,h){
        map[j].erase(i,1);
      }
      w--;i--;
    }
  }
  rep(i,h){
    bool e = false;
    rep(j,w){
      if(map[i][j]=='#')e = true;
    }
    if(e)cout << map[i]<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static int gcd(int a, int b){
		c = 0;
		if(a < b){
			int tmp = a;
			a = b;
			b = tmp;
		}
		while(b!=0){
			int r = a%b;
			a = b;
			b = r;
			c++;
		}
		return a;
	}

	static int c;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int a = sc.nextInt();
			int b = sc.nextInt();
			if((a|b)==0)break;
			System.out.println(gcd(a,b)+" "+c);
		}
	}
}

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

using namespace std;
using ll = long long;


int main()
{
    int n;
    cin >> n;
    vector<vector<ll>> a(n, vector<ll>(3));
    for(int i = 0; i < n; i++)for(int j = 0; j < 3; j++)cin >> a[i][j];
    vector<vector<ll>> dp(n + 1, vector<ll>(3));


    for(int i = 0; i < n; i++){
        dp[i + 1][0] = max(dp[i][1] + a[i][0], dp[i][2] + a[i][0]);
        dp[i + 1][1] = max(dp[i][0] + a[i][1], dp[i][2] + a[i][1]);
        dp[i + 1][2] = max(dp[i][0] + a[i][2], dp[i][1] + a[i][2]);
    }

    cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
}

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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>  // Including tree_order_statistics_node_update

using namespace __gnu_pbds;
using namespace std;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define tr(c, i) for (__typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)
#define present(c, x) ((c).find(x) != (c).end())
#define cpresent(c, x) (find(all(c), x) != (c).end())
#define minei(x) min_element(x.begin(), x.end()) - (x).begin()
#define maxei(x) max_element(x.begin(), x.end()) - (x).begin()
#define LSOne(S) (S & (-S))

#define uns(v) sort((v).begin(), (v).end()), v.erase(unique(v.begin(), v.end()), v.end())
#define acusum(x) accumulate(x.begin(), x.end(), 0)
#define acumul(x) accumulate(x.begin(), x.end(), 1, multiplies<int>());
#define bits(x) __builtin_popcount(x)
#define oo INT_MAX
#define inf 1000000000
#define MAXN 1000007
#define MOD 1000000007

const double pi = acos(-1.0);
const double eps = 1e-11;

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
int v[14][14];
int main() {
    std::ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, x;
    cin >> n >> m >> x;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j <= m; j++) {
            cin >> v[i][j];
        }
    }
    ll res = oo;
    for (int i = 0; i < (1 << n); i++) {
        ll cst = 0;
        vector<int> algo(m + 1, 0);
        for (int j = 0; j < n; j++) {
            if ((i & (1 << j)) != 0) {
                cst += v[j][0];
                for (int k = 1; k <= m; k++) {
                    algo[k] += v[j][k];
                }
            }
            bool isValid = true;
            for (int k = 1; k <= m; k++) {
                if (algo[k] < x) isValid = false;
            }
            if (isValid) {
                res = min(res, cst);
            }
        }
    }
    if (res == oo) res = -1;
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  while(cin >> n,n){
    vector<string> v;
    int d[15][15]={{}};
    int l[15]={};
    int ans;
    int dp[1<<14][14];
    int inf = 1 << 20;
    string s;
    int i,j,k;
    v.clear();
    for(i=0;i<n;i++){
      cin >> s;
      v.push_back(s);
    }
    for(i=0;i<10;i++){
      for(j=0;j<10;j++){
	d[i][j]=0;
      }
    }
    
    bool f;
    for(i=0;i<n;i++){
      f=false;
      for(j=0;j<n;j++){
	if(i==j) continue;
	if(v[j].find(v[i])!=-1) f=true;	
      }
      if(f){
	v.erase(v.begin()+i);
	i--;n--;
      }
    }
    for(i=0;i<n;i++) l[i]=v[i].size();
    
    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	if(i==j) continue;
	for(k=1;k<=v[i].size();k++){
	  if(v[i].substr(v[i].size()-k,k)==v[j].substr(0,k))
	    d[i][j]=max(d[i][j],k);
	}
      }
    }
    memset(dp,-1,sizeof(dp));
    for(i=0;i<n;i++){
      dp[1<<i][i]=l[i];
    }
    for(int bit=1;bit<(1<<n);bit++){
      for(i=0;i<n;i++){
	if(bit>>i&1) continue;
	for(j=0;j<n;j++){
	  if(~dp[bit][j]){
	    if(~dp[bit|(1<<i)][i])
	      dp[bit|(1<<i)][i]=min(dp[bit|(1<<i)][i],dp[bit][j]+l[i]-d[j][i]);
	    else
	      dp[bit|(1<<i)][i]=dp[bit][j]+l[i]-d[j][i];
	  }
	}
      }
    }
    ans=inf;
    for(i=0;i<n;i++) if(~dp[(1<<n)-1][i]) ans=min(ans,dp[(1<<n)-1][i]);
    cout << ans << endl;
    
  }
  return 0;
}

Measured memory_bytes: 2116
using System;
using System.Linq;
namespace B___Resistors_in_Parallel
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            double[] A = Console.ReadLine().Trim().Split(' ').Select(n => double.Parse(n)).ToArray();
            var sum = 0.0;
            var ans = 0.0;
            for (int i = 0; i < N; i++)
            {
                sum += 1 / A[i];
            }
            ans = 1.0 / sum;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main(){
int n,m;
char a[105][105];
cin >> n >> m;
for (int i=1;i<=n;i++){
	for (int j=1;j<=m;j++) cin >> a[i][j];
}
for (int i=1;i<=2*n;i++){
	for (int j=1;j<=m;j++) cout << a[(i+1)/2][j];
	cout << endl;
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
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 N,A,B,C;
vector<int> L;

int rec(int i, int a, int b, int c) {
  if (i==N) {
    if(!a || !b || !c) return 99999;
    return abs(a-A) + abs(b-B) + abs(c-C);
  }
  int res = rec(i+1, a, b, c);

  chmin(res, rec(i+1, a + L[i], b, c) + (a ? 10 : 0));
  chmin(res, rec(i+1, a, b + L[i], c) + (b ? 10 : 0));
  chmin(res, rec(i+1, a, b, c + L[i]) + (c ? 10 : 0));

  return res;
}

int main() {
  cin >> N >> A >> B >> C;
  L.resize(N);
  rep(i, N) cin >> L[i];
  cout << rec(0, 0, 0, 0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int T;
long long A,B,l,r,mid,MAX,mid1,mid2,a,b;
bool flag;
bool check(long long L,long long R){
	mid1=L;
	mid2=mid-L+1;
	for(int i=30;i>=0;i--)
		if(mid1+(1<<i)<=mid2-(1<<i)){
			mid1+=(1<<i);
			mid2-=(1<<i);
		}
	if(mid1>=A)
		mid1++;
	if(mid2>=B)
		mid2++;
	return mid1*mid2<MAX;
}
int main(){
	cin>>T;
	while(T--){
		cin>>A>>B;
		if(A>B)
			swap(A,B);
		MAX=A*B;
		l=0;
		r=A+B+A+B;
		while(l<r){
			mid=(l+r+1)>>1;
			a=A;
			b=mid-B+1;
			if(a>b)
				swap(a,b);
			if(mid<a)
				flag=check(1,mid);
			else
			if(mid<b)
				flag=check(1,a-1)&&check(a,mid);
			else
				flag=check(1,a-1)&&check(a,b-1)&&check(b,mid);
			if(flag)
				l=mid;
			else
				r=mid-1;
		}
		cout<<l<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define pll pair<ll,ll>
#define all(v) v.begin(),v.end()
#define mod 1000000007
#define mx 1000002
mt19937 myrand(time(0));

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(),cout.tie();
    ll k;
    cin>>k;
    ll cnt=1,x=7;
    while(x%k){
        cnt++;
        if(cnt>=1e7) break;
        x*=10;
        x+=7;
        x%=k;
        //debug()<<imie(x)<<imie(cnt);
    }
    if(x%k==0) cout<<cnt<<endl;
    else cout<<-1<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 1010
using namespace std;
long long a[MAXN],a1[MAXN],n,sum[2],used[MAXN],flag,r[MAXN],l[MAXN];
bool dele[MAXN];
vector<int> ans;
void del(int x){
    ans.push_back(x+1);
    a[x]=0;
    memset(dele,0,sizeof dele);
    memset(used,0,sizeof used);
    if(x!=0){
        dele[x-1]=1;
        a[x]+=a[x-1];
    }
    if(x!=n-1){
        dele[x+1]=1;
        a[x]+=a[x+1];
    }
    for(int i=0;i<n;i++)
        a1[i]=a[i];
    int cnt=0;
    for(int i=0;i<n;i++)
        if(dele[i]==0)
            a[cnt++]=a1[i];
    for(int i=0;i<n;i++)
        if(a[i]>0&&flag==i%2)
            used[i]=1;
    n=cnt;
}
void work(){
    int maxid=0;
    for(int i=0;i<n;i++)
        if(a[i]>a[maxid])
            maxid=i;
    PF("%lld\n%d\n",a[maxid],n-1);
    int sum=n;
    for(int i=0;i<maxid;i++){
        PF("%d\n",1);
        sum--;
    }
    for(int i=n-1;i>maxid;i--){
        PF("%d\n",sum);
        sum--;
    }
}
int main(){
    SF("%d",&n);
    for(int i=0;i<n;i++)
        SF("%lld",&a[i]);
    for(int i=0;i<n;i++)
        if(a[i]>0)
            sum[i%2]+=a[i];
    if(sum[0]==0&&sum[1]==0){
        work();
        return 0;
    }
    if(sum[0]>sum[1])
        flag=0;
    else
        flag=1;
    for(int i=0;i<n;i++){
        l[i]=i-1;
        r[i]=i+1;
    }
    for(int i=0;i<n;i++)
        if(a[i]>0&&flag==i%2)
            used[i]=1;
    while(n>1){
        /*for(int i=0;i<n;i++)
            PF("{%d}",used[i]);
        PF("\n");*/
        for(int i=0;i<n;i++){
            if(i==0||i==n-1){
                if(used[i]==0){
                    if(i==0)
                        flag^=1;
                    del(i);
                    break;
                }
            }
            else if(used[i-1]==used[i+1]){
                del(i);
                break;
            }
        }
    }
    PF("%lld\n%d\n",a[0],ans.size());
    for(int i=0;i<ans.size();i++)
        PF("%d\n",ans[i]);
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
    string start;
    cin>>start;
    string last=start;
    reverse(last.begin(),last.end());
    for(int i=0;i<last.size();i++)
    {
        if(last[i]=='b') 
        {
            last[i]='d';
        }
        else if(last[i]=='d') 
        {
            last[i]='b';   
        }
        else if(last[i]=='p') 
        {
            last[i]='q';
        }
        else if(last[i]=='q') 
        {
           last[i]='p'; 
        }
    }
    if(last==start) 
    {
     cout<<"Yes";   
     return 0;
    }
    cout<<"No";
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int selectionSort(int A[], int N)
{
  int i, j, t, sw = 0, mini;
  for(i=0;i<N-1;i++){
    mini = i;
    for(j = i;j<N;j++){
      if(A[j]<A[mini]) mini = j;
    }
    t = A[i]; A[i] = A[mini]; A[mini] = t;
    if(i != mini) sw++;
  }
  return sw;
}

int main(){
  int A[100], N, i, sw;

  cin >> N;
  for (i=0;i<N;i++) cin >> A[i];

  sw = selectionSort(A,N);

  for(i=0;i<N;i++){
    if(i>0) cout << " ";
    cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

  return 0;
}



Measured memory_bytes: 3120
v=[[3*M=998244353,s=1]]
`sed 1d|sort -nr`.lines{|e|x,d=e.split.map &:to_i
r=1
r=r%M*v.pop[1]while v[-1][0]<x+d
v<<[x,r+1]}
v.map{|_,y|s=s*y%M}
p s

Measured memory_bytes: 14356
#include<iostream>
using namespace std;
int main()
{
	int a,b,sum;
	cin>>a>>b;
	if(a>=0&&a<=5)
	    sum=0;
	else if(a>=6&&a<=12)
	    sum=b/2;
	else
	    sum=b;
	cout<<sum<<endl;
	return 0;
}

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

#define INF 0x3f3f3f3f

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

int n, m;
int to[200010], from[200010];

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

	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b;
		cin >> a >> b;
		if (a == 1) to[b] = 1;
		if (b == n) from[a] = 1;
	}

	if (to[n] == 1) {
		cout << "POSSIBLE" << endl;
		return 0;
	}

	for (int i = 2; i <= m; i++) {
		if (to[i] == 1 && from[i] == 1) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;

	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	int n;
	cin >> n;
	vector<int> a(n), b(n), c(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	for(int i = 0; i < n; ++i) cin >> b[i];
	for(int i = 0; i < n; ++i) cin >> c[i];

	int ans = b[0];
	for(int i = 1; i < n; ++i)
	{
		ans += b[i];
		if (a[i - 1] + 1 == a[i])
		{
			ans += c[a[i - 1] - 1];
		}
	}
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
int main(){
	int N; long long int P = 1e9+7; 
	cin >> N; 
  long long int AA[110] = {}; 
  long long int AG[110] = {}; 
  long long int AC[110] = {}; 
  long long int AT[110] = {}; 
  long long int CA[110] = {}; 
  long long int CG[110] = {}; 
  long long int CC[110] = {}; 
  long long int CT[110] = {}; 
  long long int GA[110] = {}; 
  long long int GG[110] = {}; 
  long long int GC[110] = {}; 
  long long int GT[110] = {}; 
  long long int TA[110] = {}; 
  long long int TG[110] = {}; 
  long long int TC[110] = {}; 
  long long int TT[110] = {};  
  long long int sum[110] = {}; 
  sum[0] = 1; sum[1] = 4; sum[2] = 16; 
  AA[2] = 1; AG[2] = 1; AC[2] = 1; AT[2] = 1; 
  CA[2] = 1; CC[2] = 1; CG[2] = 1; CT[2] = 1; 
  GA[2] = 1; GC[2] = 1; GG[2] = 1; GT[2] = 1; 
  TA[2] = 1; TC[2] = 1; TG[2] = 1; TT[2] = 1; 
  for(int i = 3; i <= N; i++){
   	AA[i] = (AA[i-1] + CA[i-1] + GA[i-1] + TA[i-1]) % P; 
    AC[i] = (AA[i-1] + CA[i-1] + TA[i-1]) % P; 
    AG[i] = (AA[i-1] + CA[i-1] + GA[i-1] + TA[i-1]) % P; 
    CA[i] = (AC[i-1] + CC[i-1] + GC[i-1] + TC[i-1]) % P; 
    CC[i] = (AC[i-1] + CC[i-1] + GC[i-1] + TC[i-1]) % P; 
    CG[i] = (CC[i-1] + GC[i-1] + TC[i-1]) % P; 
    GA[i] = (AG[i-1] + CG[i-1] + GG[i-1] + TG[i-1]) % P; 
    GC[i] = (P * 2 + CG[i-1] + GG[i-1] + TG[i-1] - AT[i-2] - AG[i-2]) % P; 
    GG[i] = (AG[i-1] + CG[i-1] + GG[i-1] + TG[i-1]) % P; 
    AT[i] = (AA[i-1] + CA[i-1] + GA[i-1] + TA[i-1]) % P; 
    CT[i] = (AC[i-1] + CC[i-1] + GC[i-1] + TC[i-1]) % P; 
    GT[i] = (AG[i-1] + CG[i-1] + GG[i-1] + TG[i-1]) % P; 
    TA[i] = (AT[i-1] + CT[i-1] + GT[i-1] + TT[i-1]) % P; 
    TC[i] = (P + AT[i-1] + CT[i-1] + GT[i-1] + TT[i-1] - AG[i-2]) % P; 
    TG[i] = (AT[i-1] + CT[i-1] + GT[i-1] + TT[i-1]) % P; 
    TT[i] = (AT[i-1] + CT[i-1] + GT[i-1] + TT[i-1]) % P; 
    sum[i] = (AA[i]+AC[i]+AG[i]+CA[i]+CC[i]+CG[i]+GA[i]+GC[i]+GG[i]+AT[i]+CT[i]+GT[i]+TA[i]+TC[i]+TG[i]+TT[i]) % P; 
  }
  cout << sum[N] << endl; 
}

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

int main() {
  string s,t; cin>>s>>t;
  string ans = "";
  vector<vector<int>> dp(s.length()+1,vector<int>(t.length()+1,0));

  for(int i=0; i<s.length(); i++) {
    for(int j=0; j<t.length(); j++) {
      // 付け加える文字のぺあが同一
      if(s[i]==t[j]) dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j]+1);
      // 付け加える文字のペアが異なる
      else dp[i+1][j+1] = max({dp[i+1][j+1], dp[i+1][j], dp[i][j+1]});
    }
  }
  //cout << dp[s.length()][t.length()] << endl;
  int i=(int)s.length(), j=(int)t.length();
  while(i>0 && j>0) {
    if(dp[i][j]==dp[i-1][j]) i--;
    else if(dp[i][j]==dp[i][j-1]) j--;
    else {
      ans = s[i-1] + ans;
      i--; j--;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 38872
#include <iostream>
using namespace std;
int main(){
  int x, a, b;
  cin >> x >> a >> b;
  int c = a - x;
  if(x > a){
    c = (-1)*c;
  }
  int d = b - x;
  if(x > b){
    d = (-1)*d;
  }
  
  if(c < d) cout << "A" << endl;
  if(d < c) cout << "B" << endl;
}
  

Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int itemCount = int.Parse(Reader.ReadLine());

        int[] items = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        Console.WriteLine(items.Select(a => a - 1).Sum());

    }


    private long GetSaidaiKouyaku(long num1, long num2) {
        long num3 = num2;
        for (int i = 2; i * i <= num3; i++) {
            while(num1 % i == 0 && num3 % i == 0) {
                num3 = num3 / i;
            }
        }
        return num1 * num3;
    }





    public class Reader
    {
        static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"


3
3 4 6

";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 13376
#include<bits/stdc++.h>
using namespace std;
#define sz 10010
#define MOD 1000000007
#define ll long long

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


	long double n, a, prod; cin >> n; prod = 1;
	for (ll i = 0; i < n; i++) {
		cin >> a;
		if (a == 0)
		{
			prod = 0;
			continue;
		}
		if (prod > 0)
		{
			if (log10(a) + log10(prod) > 18.0)
			{
				prod = -1;
				continue;
			}
			// cout << fixed << setprecision(6)  << log10(a) + log10(prod);
			prod *= a;
			if (prod > 1e18)
			{
				prod = -1;
				continue;
			}
			// cout << " :" << fixed << setprecision(0) << prod << "\n";
		}
	}
	cout << fixed << setprecision(0) << prod;


	return 0;
}

Measured memory_bytes: 3884
import sys

n = int(input())

b = [int(item) for item in input().split()]

def dfs(b_sub, ans):
  if len(b_sub) == 0:
    for a in ans[::-1]:
      print(a)
    sys.exit()
  takeable = []
  for i, item in enumerate(b_sub):
    if i+1 == item:
      takeable.append(i)
  if len(takeable) == 0:
    print(-1)
    sys.exit()
  for item in takeable[::-1]:
    tmp = b_sub
    taken = tmp.pop(item)
    ans.append(taken)
    dfs(tmp, ans)
  
print(dfs(b, []))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


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

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
using namespace std;
#define int long long
vector<int> dp,dpf;
signed main(){
    int n, m, a, prev, ans = 0, maxs = 0;
    cin >> n >> m >> prev;
    dp.resize(m+2);dpf.resize(m+2);
    for(int i = 1; i < n; i++){
        cin >> a;
        ans += (a+m-prev)%m;
        if(a == prev)continue;
        if(a < prev){
            dp[0]+=m-prev-1;
            dpf[0]++;
        }
		dp[a] -= (a-prev+m-1)%m;
        dpf[prev+1]++;
        dpf[a]--;
        prev = a;
    }
    for(int i = 0; i <= m; i++){
        if(i!=m)dpf[i+1] += dpf[i];
        dpf[i] += dp[i];
        if(i)dpf[i] += dpf[i-1];
        maxs = max(maxs, dpf[i]);
    }
    cout << ans-maxs << endl;

}


Measured memory_bytes: 1792
#include <stdio.h>

int main() {
    int n, x, cou;
    while (1) {
        cou = 0;
        scanf("%d %d", &n, &x);
        if ((n == 0) && (x == 0)) {break;}
        for (int i=1; i<=n; i++) {
            for (int j=1; j<=n; j++) {
                for (int k=1; k<=n; k++) {
                    if ((i == j) || (j == k) || (k == i)) {continue;}
                    if (i + j + k == x) {
                        cou++;
                    }
                }
            }
        }
        printf("%d\n", cou / 6);
    }
    return 0;
}



Measured memory_bytes: 2056
#include <bits/stdc++.h>
#define FOR(i,s,e) for(int i=(s);i<(e);i++)
#define REP(i,n) FOR(i,0,n)
#define all(v) (v).begin(),(v).end()
#define pb(a) push_back(a)
using namespace std;
typedef long long LL;
typedef pair<int, int> P;

LL gcd(LL m, LL n){
    if(n==0) return m;
    return gcd(n, m%n);
}

LL lcm(LL m, LL n){
    return m/gcd(m,n)*n;
}

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

    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;

    LL l = lcm(n, m);
    LL N = l/n, M = l/m;
    for(int i=0, j=0; i<n && j<m; i+=M, j+=N){
        if(s[i] != t[j]){
            puts("-1");
            return 0;
        }
    }
    cout << l << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int x,y;
	scanf("%d %d",&x,&y);
	if(x>y){
	printf("a > b\n");
	}
	else if(x<y){
	printf("a < b\n");
	}
	else{
	printf("a == b\n");
	}
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <string>
#include <cstring>

using namespace std;

int INF = 1e9 + 7;
short mod = 13;
string str;
long long dp[100000][13];

long long dfs(int now, int m){
    if(now == str.size()) return m == 5;
    if(~dp[now][m]) return dp[now][m];
    long long res = 0;
    if(str[now] == '?'){
        for(int i = 0; i < 10; i++){
            res += dfs(now + 1, (m * 10 + i) % mod);
            res %= INF;
        }
    }else{
        res = dfs(now + 1, (m * 10 + str[now] - '0') % mod);
        res %= INF;
    }
    return dp[now][m] = res;
}

int main(){
    cin >> str;
    memset(dp, -1, sizeof(dp));
    cout << dfs(0, 0) << "\n";
}

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

#define for_(i,a,b) for(int i=a;i<b;++i)

struct Cake {
	int w, d;
	Cake() {}
	Cake(int _w, int _d) : w(_w), d(_d) {}
	bool operator < (const Cake& a) const { return this->w * this->d < a.w * a.d; }
};

int n, w, d;

int main() {
	while (scanf("%d %d %d", &n, &w, &d), w) {
		vector< Cake > cakes;
		cakes.push_back(Cake(w, d));
		
		for_(i,0,n) {
			int p, s; scanf("%d %d", &p, &s); --p;
			
			Cake cp = cakes[p];
			s %= (cp.w + cp.d);
			Cake a, b;
			
			if (s < cp.w) {
				a = Cake(cp.w - s, cp.d);
				b = Cake(s, cp.d);
			} else {
				a = Cake(cp.w, cp.d - s + cp.w);
				b = Cake(cp.w, s - cp.w);
			}
			
			cakes.erase(cakes.begin() + p);
			cakes.push_back(min(a, b));
			cakes.push_back(max(a, b));
		}
		
		sort(cakes.begin(), cakes.end());
		
		for_(i,0,n+1) {
			Cake ci = cakes[i];
			if (i < n) cout << ci.w * ci.d << " ";
			else cout << ci.w * ci.d << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 501
#define MAX_M 200001
#define MAX_Q 100001
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define FOR(i, a, b) for(ll i=a; i<b; i++)
#define REP(i, n) for(ll i=0; i<n; i++)
#define REV(i, n) for(ll i=n-1; i>=0; i--)
#define ALL(v) v.begin(), v.end()
#define pb push_back
const ll INF = 9e18;
ll n, m, q, a[MAX_N][MAX_N], x[MAX_N][MAX_N];
P lr[MAX_M], pq[MAX_Q];

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}

signed main(){
	cin >> n >> m >> q;
	REP(i, m){ cin >> lr[i].first >> lr[i].second; lr[i].first--; lr[i].second--; }
	REP(i, q){ cin >> pq[i].first >> pq[i].second; pq[i].first--; pq[i].second--; }

	Fill(x, 0); Fill(a, 0);
	REP(i, m) a[lr[i].first][lr[i].second]++;
	REP(i, n) REP(j, n) x[i][j] = (j >= 1) ? x[i][j-1] + a[i][j] : a[i][j];

	REP(i, q){
		ll ret = 0;
		FOR(j, pq[i].first, pq[i].second+1){
			// cout << x[j][pq[i].second] << " " << x[j][pq[i].first] << endl;	
			if(pq[i].first - 1 >= 0) ret += x[j][pq[i].second] - x[j][pq[i].first - 1];
			else ret += x[j][pq[i].second];
		}
		cout << ret << endl;
	}
    return 0;
}

Measured memory_bytes: 9472
N, M = map(int, input().split())
H = list(map(int, input().split()))
AB = [list(map(int, input().split())) for _ in range(M)]

bad = set()
for i in range(M):
    if H[AB[i][0]-1] < H[AB[i][1]-1]:
        bad.add(AB[i][0])
    elif H[AB[i][0]-1] > H[AB[i][1]-1]:
        bad.add(AB[i][1])
    else:
        bad.add(AB[i][0])
        bad.add(AB[i][1])
print(N-len(bad))


Measured memory_bytes: 34008
#include <stdio.h>

void insertionSort(int A[], int N) {
   int i, j;
   int tmp;

   for (i = 1; i < N; i++) {
       for (j = 0; j < N; j++) {
           printf("%d", A[j]);
           if (j != N-1)
               printf(" ");
           else
               printf("\n");
       }

       tmp = A[i];
       j = i-1;

       while (j >= 0 && A[j] > tmp) {
           A[j+1] = A[j];
           j--;
       }
       A[j+1] = tmp;
   }
}

int main() {
   int N, A[1001];
   int i;

   scanf("%d", &N);

   for (i = 0; i < N; i++)
       scanf("%d", &A[i]);

   insertionSort(A, N);

   for (i = 0; i < N; i++) {
       printf("%d", A[i]);
       if (i != N-1)
           printf(" ");
       else
           printf("\n");
   }

   return 0;
}

Measured memory_bytes: 1780
import fractions
from functools import reduce

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

def lcm_list(l):
    return reduce(lcm, l, 1)


ans = 0

dev = 10 ** 9 + 7

n = int(input())

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

z = lcm_list(a)



for i in a:
    ans += z // i
    #ans = ans % dev

print(ans%dev)

Measured memory_bytes: 6108
n= int(input())
a = list(map(int,input().split()))
s=0
k=0
top=[]
bottom=[]
t=0
ans=1000
ka=0
while a[s]==a[s+1] and s<n-1:
    s+=1
    if s == n - 1:
        break
if s==n-1:
    print(ans)
else:
    if a[s]>a[s+1]:
        k=-1
        t=1
    else:
        k=1

    while s<n-1:
        while a[s]*k <= a[s+1]*k and s<n-1:
            s+=1
            if s==n-1:
                break
        if k ==-1:
            bottom.append(a[s])
        else:
            top.append(a[s])
        k *= -1
        s+=1
    if k == 1:
        top.append(a[-1])
    else:
        bottom.append(a[-1])
    if t==1:
        for i in range(len(top)):
            ka+=ans//bottom[i]
            ans = ans % bottom[i]
            ans += ka*top[i]
            ka = 0
    else:
        for i in range(len(top)):

            if i== 0:
                ka += ans // a[i]
                ans = ans % a[i]
                ans += ka * top[i]
                ka = 0
            else:
                ka+=ans//bottom[i-1]
                ans = ans % bottom[i-1]
                ans += ka*top[i]
                ka = 0
    print(ans)

Measured memory_bytes: 9296