akhauriyash/Code-Regression huggingface dataset:
#mathモジュールをインポートする
import math
try:
    while True:
        a,b = map(int,input().split())
        #最小公約数
        num1 = math.gcd(a,b)
        #最大公倍数
        num2 = int(a * b / num1)
        print(str(num1) + " " + str(num2))
#EOFErrorをひろいコードを終了する
except EOFError:
    pass


Measured memory_bytes: 5656
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))
A.sort()


if N%2==1:
    if A[0]!=0:
        print(0)
        exit()
    for i in range(1,N)[::2]:
        if A[i]==-int(-i//2)*2 and A[i+1]==-int(-i//2)*2:
            pass
        else:
            print(0)
            exit()
    print(2**(N//2)%(10**9+7))
else:
    for i in range(N)[::2]:
        if A[i]==-int(-i//2)*2+1 and A[i+1]==-int(-i//2)*2+1:
            pass
        else:
            print(0)
            exit()
    print(2**(N//2)%(10**9+7))
    
    


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


long long K, A[100000];

int main(){
    cin >> K;
    for(int i = 0; i < K; i++){
        cin >> A[i];
    }
    long long l = 2, r = 2;
    for(int i = K-1; i >= 0; i--){
        long long min_pair = (l + A[i] - 1) / A[i];
        long long max_pair = r / A[i];
        if((l % A[i] != 0) && (r % A[i] != 0) && (l / A[i] == r / A[i])){
            cout << -1 << endl;
            //cout << i << ", " << l << ", " << r << endl;
            return 0;
        }
        l = min_pair * A[i];
        r = max_pair * A[i] + (A[i] - 1);
        //cout << i << ", " << l << ", " << r << endl;
    }
    cout << l << " " << r << endl;
}

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

int main() {
  int n, aliss, bob;
  cin >> n;
  vector<int> cards(n);
  aliss = 0;
  bob = 0;
  for (int i = 0; i < n; i++){
    cin >> cards.at(i);
  }
  
  sort(cards.begin(), cards.end());
  reverse(cards.begin(), cards.end());
  
  for (int i = 0; i < n; i += 2){
    aliss += cards.at(i);
  }
  if (n > 1){
    for (int i = 1; i < n; i += 2){
      bob += cards.at(i);
    }
  }
  cout << aliss - bob << endl;
}

Measured memory_bytes: 256
#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>;

void Main(){
    int n; cin >> n;
    vector<P> d(n);
    rep(i, n){
        cin >> d[i].fi >> d[i].se;
    }
    sort(rall(d));
    cout << d[0].fi + d[0].se << endl;
    return;
}

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

Measured memory_bytes: 3952
#include <stdio.h>
int main(){
    int a,b,k=-200000000,
        s[5]={};
    scanf("%d%d",&a,&b);
    s[0]=a+b;
    s[1]=a-b;
    s[2]=a*b;
    for(int i=0;i<3;i++){
        if(k<s[i]) k=s[i];
    }
    printf("%d",k);
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();

		int[] test = new int[n];

		for (int i = 0; i < n; i++) {
			test[i] = sc.nextInt();
		}
		sc.close();

		for (int i = 0; i < n - k; i++) {
			printBool(test[i + k] > test[i]);
		}

	}

	public static void printBool(boolean bool) {
		print(bool ? "Yes" : "No");
	}

	public static void print(Object obj) {
		System.out.println(obj);
	}

}


Measured memory_bytes: 60408
#include <iostream>
#include <fstream>
using namespace std;
const int nmax=5025;
int dp[2][nmax][nmax];
int a[nmax],l[nmax],r[nmax];
int n,i,j,k,ind,n1,n2,ans;
bool check()
{
    ind=1;
    for(j=n1;j>=1;j--)
    {
        while(ind<=n2&&l[j]+r[ind]<k) ind++;
        ind--;
        if(l[j]+r[ind]>=k-a[i])
            return 1;
    }
    return 0;
}
int main()
{
    //freopen("data.in","r",stdin);
    cin>>n>>k;
    dp[0][0][0]=1;
    for(i=1;i<=n;i++)
    {
        cin>>a[i];
        for(j=0;j<=k;j++)
            dp[0][i][j]=dp[0][i-1][j];
        for(j=k-a[i];j>=0;j--)
            dp[0][i][j+a[i]]|=dp[0][i][j];
    }
    dp[1][n+1][0]=1;
    for(i=n;i>=1;i--)
    {
        for(j=0;j<=k;j++)
            dp[1][i][j]=dp[1][i+1][j];
        for(j=k-a[i];j>=0;j--)
            dp[1][i][j+a[i]]|=dp[1][i][j];
    }
    for(i=1;i<=n;i++)
    {
        n1=n2=0;
        for(j=0;j<k;j++)
            if(dp[0][i-1][j])
               l[++n1]=j;
        for(j=0;j<k;j++)
            if(dp[1][i+1][j])
               r[++n2]=j;
        if(!check()) ++ans;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 197120
#include<stdio.h>
int n,A[50];

int solve(int i, int m){
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void){
    int q,M,i;
    scanf("%d",&n);
    for(i=0; i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%d",&M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2044
import java.util.*;

public class Main{ 

	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		SortStrategy bubble = new Bubble(scan.nextInt());
		bubble.loadSequence(scan);
		scan.close();
		SortContext context = new SortContext(bubble);
		System.out.println(context);
		System.out.println(context.swapTimes());
	}

}

abstract class SortStrategy{
	int swapTimes = 0;
	int seqLength;
	ArrayList<Integer> seq = new ArrayList<Integer>();
	public SortStrategy(int n){
		seqLength = n;
	}
	public void loadSequence(Scanner scan){
		for(int i=0; i<seqLength; i++)
			seq.add(scan.nextInt());
	}
	int getSwapTimes(){
		return swapTimes;
	}
	abstract ArrayList<Integer> sort();
}
class Bubble extends SortStrategy{
	public Bubble(int n){
		super(n);
	}
	@Override
	public ArrayList<Integer> sort(){
		for(int i=0; i<seq.size();i++)
			for(int j=seq.size()-1; i<j ;j--)
				if(seq.get(j)<seq.get(j-1)){
					Collections.swap(seq, j, j-1);
					swapTimes++;
				}
		return seq;
	}

}
class SortContext{
	SortStrategy strategy;
	public SortContext(SortStrategy s){
		this.strategy = s;
	}
	public String toString(){
		String tmp = "";
		for(Iterator<Integer> iter = strategy.sort().iterator();iter.hasNext();)
			tmp += iter.next() + " ";
		return tmp.trim();
	}

	public int swapTimes(){
		return strategy.getSwapTimes();
	}
}

Measured memory_bytes: 20140
#include <stdio.h>
struct time{
	int month,day,hour,minute;
	time() {};
}f;
#define max(a,b) ((a>b)?a:b)
int ID[1005][2];
int main() {
	int n,i,j,k;char T[5];while (scanf("%d",&n)!=EOF && n) {
		for (i=0;i<1005;ID[i][0]=-1,ID[i][1]=0,i++);j=k=0;
		while (n--) {
			scanf("%d/%d %d:%d",&f.month,&f.day,&f.hour,&f.minute);
			scanf("%s %d",&T,&i);
			if (j==f.day && k==f.month) {
				if (i) {
					if (T[0]=='I') ID[i][0]=f.hour*60+f.minute;
					else {
						if (ID[0][0]!=-1) ID[i][1]+=f.hour*60+f.minute-max(ID[0][0],ID[i][0]);
						ID[i][0]=-1;
					}
				} else {
					if (T[0]=='I') ID[0][0]=f.hour*60+f.minute;
					else {
						j=f.hour*60+f.minute;
						for (i=1;i<1005;i++) if (ID[i][0]!=-1) ID[i][1]+=j-max(ID[i][0],ID[0][0]);
						ID[0][0]=-1;j=f.day;
					}
				}
			} else {
				for (j=0;j<1005;ID[j++][0]=-1);
				j=f.day,k=f.month;
				ID[i][0]=f.hour*60+f.minute;
			}
		}
		for (i=2,j=1;i<1005;i++) if (ID[i][1]>ID[j][1]) j=i;
		printf("%d\n",ID[j][1]);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

int partition(vector<int>& A,int p,int r) {
  int x = A[r];
  int i = p - 1;
  for(int j=p;j<r;j++) {
    if(A[j] <= x) {
      i++;
      swap(A[i],A[j]);
    }
  }
  swap(A[i+1],A[r]);
  return i+1;
}

int main() {
  int n;
  scanf("%d",&n);
  vector<int> A(n);
  for(int i=0;i<n;i++) {
    scanf("%d ",&A[i]);
  }
  int p = partition(A,0,n-1);
  for(int i=0;i<n;i++) {
    if(i == p) {
      printf("[");
      printf("%d",A[i]);
      printf("]");
    }
    else {
      printf("%d",A[i]);
    }

    if(i+1 == n)
      printf("\n");
    else
      printf(" ");
  }
}

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

L = sorted(L)

import bisect

# 二本を決める
ans = 0
for i in range(N - 2):
  for j in range(i + 1, N - 1):
    # L[i] + L[j] より短い棒で且つjより大きいインデックスを数える
    ind = bisect.bisect_left(L, L[i] + L[j])
    num = ind - (j + 1)
    ans += max(num, 0)
    
print(ans)

Measured memory_bytes: 9376
import fractions
N, M = map(int, input().split())
a_array = list(map(int, input().split()))

Q = 2 ** 35

two_count = fractions.gcd(a_array[0], Q)
lcm = 1

for a in a_array:
    aa = a // 2
    if two_count != fractions.gcd(a, Q):
        print(0)
        exit()
    lcm = int(aa * lcm) // fractions.gcd(aa, lcm)
    if lcm > M:
        print(0)
        exit()

# ans = ((M//lcm)+1) // 2
ans = (M-lcm) // (2*lcm) + 1
print(int(ans))


Measured memory_bytes: 89648
using System;
using System.Linq;

namespace atcoder.abc169.a
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputArray = getIntParams();
            int X = inputArray[0];
            int Y = inputArray[1];

            Console.WriteLine(X * Y);
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }

    }
}


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


ll gcd(ll x,ll y){
    if(x > y) swap(x,y);
    if(x == 0) return y;
    return gcd(x, y%x);
};


int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;

    ll l = c*d/gcd(c,d);

    ll cnt_a = a-1;
    cnt_a -= (a-1)/c + (a-1)/d - (a-1)/l;

    ll cnt_b = b;
    cnt_b -= b/c + b/d - b/l;

    cnt_b -= cnt_a;
    cout << cnt_b << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
#define PI 3.141592653589793
 

int main(){
 vector<vector<char>> c(3,vector<char>(3));
  rep(i,3){
    rep(j,3){
      cin >> c.at(i).at(j);
    }
  }
  cout << c.at(0).at(0) << c.at(1).at(1) <<c.at(2).at(2) << endl;
}

Measured memory_bytes: 256
import std.stdio;
import std.math;

const int INF = 99999999;
const int V = 1111;
int[V] b;
double[V] x, y;
double[V][V] cost;
int[V][V] path;
int n, m, s, g, s0, g0;

void main(){
	while (scanf("%d", &n), n) {
		foreach (i; 0..n) scanf("%d %lf %lf", &b[i], &x[i], &y[i]);
		foreach (i; 0..n) {
			foreach (j; 0..n) {
				if (i == j) {
					cost[i][j] = 0;
					path[i][j] = n;
				}else if (distance(i, j) <= 50) {
					cost[i][j] = distance(i, j);
					path[i][j] = i;
				}else {
					cost[i][j] = INF;
					path[i][j] = n;
				}
			}
		}
		
		warshall_floyd();

		scanf("%d", &m);
		foreach (i; 0..m) {
			scanf("%d %d", &s, &g);
			foreach (j; 0..n) {
				if (b[j] == s) s0 = j;
				if (b[j] == g) g0 = j;
			}
			printPath(s0, g0);
			writeln();
		}
	}
}

double distance(int i, int j){
	return sqrt((x[i] - x[j])^^2 + (y[i] - y[j])^^2);
}

void warshall_floyd(){
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				if (cost[i][j] > cost[i][k] + cost[k][j]) {
					cost[i][j] = cost[i][k] + cost[k][j];
					path[i][j] = path[k][j];
				}
			}
		}
	}
}

void printPath(int i, int j){
	if (path[i][j] != n) {
		printPath(i, path[i][j]);
		write(" ", b[j]);
	}else if (i == j) {
		write(b[j]);
	}else {
		write("NA");
	}
}

Measured memory_bytes: 25196
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
x,y = ips()
a = []
for i in range(x):
    a.append(iprow())
ans=0
for i in range(x):
    p = a[i]
    for k in range(i+1,x):
        q = a[k]
        s = 0
        for l in range(y):
            s+=pow(p[l]-q[l],2)
        if math.sqrt(s) == int(math.sqrt(s)):
            ans+=1
print(ans)

Measured memory_bytes: 22328
//============================================================================
// Name        : template.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <set>
#include <vector>
#include <string.h> // for memset in CF judge.
using namespace std;
#define _CRT_SECURE_NO_DEPRECATE // suppress some compilation warning messages (for VC++ users)
// Shortcuts for "common" data types in contests
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef set<int> si;
typedef map<string, int> msi;
// To simplify repetitions/loops, Note: define your loop style and stick with it!
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define REP(i, a, b) \
for (int i = int(a); i <= int(b); i++) // a to b, and variable i is local!
#define forn(i,n) \
for (int i =0; i<(n); i++)
#define TRvi(c, it) \
for (vi::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvii(c, it) \
for (vii::iterator it = (c).begin(); it != (c).end(); it++)
#define TRmsi(c, it) \
for (msi::iterator it = (c).begin(); it != (c).end(); it++)
#define INF 2000000000 // 2 billion
// If you need to recall how to use memset:
#define MEMSET_INF 127 // about 2B
#define MEMSET_HALF_INF 63 // about 1B
//memset(dist, MEMSET_INF, sizeof dist); // useful to initialize shortest path distances
//memset(dp_memo, -1, sizeof dp_memo); // useful to initialize DP memoization table
//memset(arr, 0, sizeof arr); // useful to clear array of integers
int a[10000005];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	ll n; cin >> n;
	memset(a, 0, sizeof a);
	ll ans = 0;
	for(ll i = 1; i <= n; i++) {
		ll j = i;
		while (j <= n ) {
			a[j]++;
			j += i;
		}
	}
	for(ll i= 1; i <= n; i++) {
		ans += a[i] * i;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 42704
#include <cstdio>
typedef long long LL;

LL x, k, d, p, a, b;

int main() {
    scanf("%lld%lld%lld", &x, &k, &d);
    if (x < 0) x = -x;
    p = x / d;
    if (p >= k) {
        printf("%lld", x - d * k);
    }
    else {
        k -= p;
        x %= d;
        if (k & 1) x -= d, x = -x;
        printf("%lld", x);
    }
}


Measured memory_bytes: 1732
#include <iostream>

#include <cstdlib>

int main() {
  long long X, K, D;
  std::cin >> X >> K >> D;

  long long L = std::abs(X) / D;
  std::cerr << "L = " << L << '\n';

  if (L >= K) {
    std::cout << (std::abs(X) - K * D) << '\n';
    return 0;
  }

  long long M = K - L;
  std::cerr << "M = " << M << '\n';
  long long Y = std::abs(X) % D;
  std::cerr << "Y = " << Y << '\n';
  if (M % 2 == 0) {
    std::cout << Y << '\n';
  } else {
    std::cout << std::abs(Y - D) << '\n';
  }
}


Measured memory_bytes: 3640
#include <cstdio>

int N, A, B;
char S[200000];

int main()
{
	scanf("%d%d%d", &N, &A, &B);
	scanf("%s", S);

	int Oversea = 0, Def = 0;
	for (int i = 0; i < N; i ++)
	{
		int R = 0;
		if (S[i] == 'a' && (Def + 1 <= A + B))
		{
			Def ++;
			R = 1;
		}
		if (S[i] == 'b' && (Def + 1 <= A + B) && (Oversea + 1) <= B)
		{
			R = 1;
			Def ++;
			Oversea ++;
		}
		printf((R == 0) ? "No\n" : "Yes\n");
	}
	return 0;
}

Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ERedScarf solver = new ERedScarf();
        solver.solve(1, in, out);
        out.close();
    }

    static class ERedScarf {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = in.readIntArray(n);

            int[] b = new int[n];
            for (int i = 0; i < n; i++) {
                b[i] = a[i] ^ a[(i + 1) % n];
            }

            int[] answer = new int[n];
            answer[0] = 0;
            for (int i = 1; i < n; i++) {
                answer[i] = answer[i - 1] ^ b[i - 1];
            }

            int xor = 0;
            for (int x : answer)
                xor ^= x;
            int offset = a[0] ^ xor ^ answer[0];

            for (int i = 0; i < n; i++) {
                answer[i] ^= offset;
            }

            out.println(Util.join(answer));
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readIntArray(int n) {
            int[] x = new int[n];
            for (int i = 0; i < n; i++) {
                x[i] = nextInt();
            }
            return x;
        }

    }

    static class Util {
        public static String join(int... i) {
            StringBuilder sb = new StringBuilder();
            for (int o : i) {
                sb.append(o);
                sb.append(" ");
            }
            if (sb.length() > 0) {
                sb.deleteCharAt(sb.length() - 1);
            }
            return sb.toString();
        }

        private Util() {
        }

    }
}



Measured memory_bytes: 57092
#include <bits/stdc++.h>
using namespace std;
#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(b)-1;i>=(a);--i)
#define ALL(a) a.begin(),a.end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;
const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
    if (a < b) { a = b; return true; }
    return false;
}
template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp);
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v);

template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
    os << "(" << p.first << ":" << p.second << ")";
    return os;
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
    os << "{";
    int a = 0;
    for (auto &tp : mp) {
        if (a) os << ", "; a = 1;
        os << tp;
    }
    return os << "}";
}
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

ll gcd(ll a, ll b) {
    if (a > b) swap(a, b);
    if (a == 0) return b;
    return gcd(a, b % a);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    for (;;) {
        ll H, h, m, s; cin >> H >> h >> m >> s;
        if (H == 0) break;

        ll M = 119 * H - 1;

        ll x = ((h * 60 + m) * 60 + s) * M;
        ll n = (x-1) / (3600 * H) + 1;

        ll y = 3600 * H * n;
        ll hour = (y / M / 3600) % H;
        ll minute = (y / M / 60) % 60;
        ll sec = y % (60 * M);

        ll d = M;
        ll g = gcd(d, sec);
        sec /= g, d /= g;

        if (hour == 0 and minute == 0 and sec == 0) {
            ++n;
            ll y = 3600 * H * n;
            ll hour = (y / M / 3600) % H;
            ll minute = (y / M / 60) % 60;
            ll sec = y % (60 * M);

            ll d = M;
            ll g = gcd(d, sec);
            sec /= g, d /= g;

            cout << hour << " " << minute << " " << sec << " " << d << endl;
            continue;
        }

        cout << hour << " " << minute << " " << sec << " " << d << endl;
    }

    return 0;
}




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

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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> llVEC;
typedef vector<P> PVEC;
typedef priority_queue<P,PVEC,greater<P> > PQ;
typedef priority_queue<ll, llVEC, greater<ll> > llPQ;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n-1; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> &vec){ return (ll)vec.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>> &pq) {return (ll)pq.size(); }
template<typename T>
ll sz(priority_queue<T, vector<T>, greater<T>> &pq) {return (ll)pq.size(); }
ll sz(string &s) {return (ll)s.size(); } 
ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }
ll lcm(ll a,ll b){ return a / gcd(a,b) * b; }
bool checkindex(ll i,ll n){ return (i < n && i >= 0); }
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

#define SEG_LEN (1 << 21)

ll seg[SEG_LEN*2];

void update(ll ind,ll v){
    ind += SEG_LEN;
    seg[ind] = v;
    while(1){
        ind /= 2;
        if(ind <= 0) break;
        seg[ind] = max(seg[ind*2],seg[ind*2+1]);
    }
    return;
}

ll find(ll l, ll r){
    l += SEG_LEN; r += SEG_LEN;
    ll res = 0;
    while(l < r){
        if(l % 2 == 1){
            res = max(res,seg[l]);
            l++;
        }
        l /= 2;
        
        if(r % 2 == 1){
            res = max(res,seg[r-1]);
            r--;
        }
        r /= 2;
    }
    return res;
}

int main(){
    ll n,k;
    cin >> n >> k;

    ll a;
    rep(i,0,n){
        cin >> a;
        update(a,find(max(0LL,a-k),a+k+1)+1);
    }

    cout << find(0,300001) << endl;


    return 0;
}



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

typedef long long ll;
const int mod = 1e9 + 7;

int main() {
    int n, k;
    cin >> n >> k;
    ll s[n + 5];
    memset(s, 0, sizeof s);
    for(int i = 1; i <= n + 1; i++)
        s[i] = s[i - 1] + i;
    int ans = 0;
    for(int i = k; i <= n + 1; i++) {
        ll v = s[n + 1] - s[n - i + 1];
        ll u = s[i];
        ans = ((ll) ans + v - u + 1) % mod;
    }
    cout << ans;
}


Measured memory_bytes: 5160
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	int N;
	int A;
	scanf("%d", &N);
	scanf("%d", &A);

	if(N%500 <= A){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}


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

bool acgt(char ch)
{
  char atgc[]="ACGT";
  for(int j=0 ; j<4 ; ++j)
  {
      if(ch==atgc[j])
      {
        return true;
      }
  }
  return false;
}

int main()
{
	int n;
  	cin>>n;
  	int ans=0;
  	vector<int> values(n);
  	for(int i=0 ; i<n ; ++i)
    cin>>values[i];
  	int cost;
  	for(int j=0 ; j<n ; ++j)
    {
    	cin>>cost;
  		ans+=max(values[j]-cost,0);
    }
  	cout<<ans<<endl;
  	
	return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve(args);
    }

    public void solve(String[] args) {
        MyScanner scanner = new MyScanner();
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        System.out.println((int)Math.ceil((double)(a + b) /2));
    }

    private class MyScanner {
        String[] s;
        int i;
        BufferedReader br;
        String reg = " ";
        MyScanner () {
            s = new String[0];
            i = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        public String next() {
            try {
                if (i < s.length) return s[i++];
                String line = br.readLine();
                while (line.equals("")) {
                    line = br.readLine();
                }
                s = line.split(reg, 0);
                i = 0;
                return s[i++];
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        public int nextInt() {
            try {return Integer.parseInt(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public double nextDouble() {
            try {return Double.parseDouble(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
        public long nextLong()  {
            try {return Long.parseLong(next());} catch (Exception e) {e.printStackTrace();}
            return -1;
        }
    }
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define RST(i,n) memset(i,n,sizeof i)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define X first
#define Y second
#define mkp make_pair
#define pb push_back
#define eb emplace_back
#define pob pop_back
#ifdef cold66
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<", ";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // cold66
//}
template<class T> inline bool chkmax(T &a, const T &b) { return b > a ? a = b, true : false; }
template<class T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;

const ll MAXn=1e5+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=0x3f3f3f3f;

ll chk(ll x){
  x*=2;
  REP1(i,sqrt(x)){
    if( x%i==0 ){
      ll tmp = x/i;
      if( abs(tmp-i)==1 && tmp*i==x ) return min(tmp,i);
    }
  }
  return INF;
}
int main(){
  IOS();
  ll n;
  cin>>n;
  ll x = chk(n);
  debug(x);
  if( x==INF ) return cout<<"No"<<endl,0;
  cout<<"Yes"<<endl;
  vector<ll> v[MAXn];
  ll cur = 1;
  ll mx = 0;
  while( cur<=n ){
    REP1(i,x){
      if( cur>n ) break;
      for(int j=0;j+i<=x;j++){
        if( cur>n ) break;
        v[j].eb(cur);
        v[j+i].eb(cur);
        chkmax(mx,j+i);
        cur++;
      }
    }
  }
  cout<<x+1<<endl;
  REP(i,mx+1){
    cout<<SZ(v[i])<<' ';
    for( auto it:v[i] ) cout<<it<<' ';
    cout<<endl;
  }
}


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

#define endl '\n'
#define ll long long
#define rint register int
#define minpq priority_queue <int, vector<int>, greater<int> >
#define maxpq  priority_queue <int>

#define re register
#define pb(x) push_back(x);
#define ce(x) cout << x << '\n';

using db = long double;
using pll = pair < ll, ll >;
#define scan(a, n) 		for(int i = 0; i < n; i++)cin >> a[i];

#define rep(i,x,n,inc) for(i=x ; i<n ; i+=inc)
#define repr(i,x,n,inc) for( i=x ; i>n ; i+=inc)
#define all(a)      (a).begin(),(a).end()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define hell 1000000007
#define infl LLONG_MAX

#define Foxen(i,s) for (i=s.begin(); i!=s.end(); i++)
#define Fill(s,v) memset(s,v,sizeof(s))
#define cout_p(x, p) cout << fixed << setprecision((p)) << x << endl     //print with precision

#define tc(tt) \
    ll tt;    \
    cin >> tt; \
    for (ll _tt = 0; _tt < tt; _tt++) // testcase 

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

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll t, i, x, j, y, 	z, k, n;
	cin >> n;
	z = n + n * n + n * n * n;
	ce(z)
}


Measured memory_bytes: 3608
from itertools import combinations

N = int(input())
L = list(map(int, input().split()))

ans = 0
for v in combinations(L, 3):
    v = sorted(v)
    if v[0] == v[1] or v[1] == v[2]:
        continue

    if v[0] >= v[1] + v[2] or v[2] >= v[1] + v[0]:
        continue

    ans += 1

print(ans)

Measured memory_bytes: 68432
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>
#define pb push_back

#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

ll gcd(ll a, ll b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

ll keta(ll n){
  string s = to_string(n);
  ll num = s.size();
  return num;
}

const ll INF = 1LL << 60;

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

struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w){}
};
using Graph = vector<vector<Edge>>;
using P = pair<ll, int>;


int main(){
  ll n,k; cin >> n >> k;
  vl a(n),s(n+1);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
    s[i+1] += s[i] + a[i];
    s[i+1] %= k;
  }

  map<ll,ll> C;
  queue<ll> q;
  ll ans = 0LL;
  rep(i,n+1) {
    ans += C[s[i]];
    C[s[i]]++;
    q.push(s[i]);
    if(q.size() == k){
      C[q.front()]--;
      q.pop();
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 17536
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
  ios::sync_with_stdio(false);
  ll H, W;
  cin >> H >> W;
  ll ret = 0;
  if (W == 1 || H == 1) {
    cout << 1 << endl;
  } else if (W % 2 == 0 || H % 2 == 0) {
    cout << H * W / 2 << endl;
  } else {
    cout << H * W / 2 + 1 << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,i,d;
vector<pair<int,int>> v,ans;
int main(){
    scanf(" %d",&n);
    for(i=0;i<n;i++){
        scanf(" %d",&d);
        v.push_back({d,i});
    }
    sort(v.begin(),v.end());
    int mid=n/2;
    for(i=0;i<n;i++){
        if(i<mid)     ans.push_back({v[i].second,v[mid].first});
        if(i>=mid)    ans.push_back({v[i].second,v[mid-1].first});
    }
    //cout << v[mid].first << ' ' << v[mid-1].first << endl;
    sort(ans.begin(),ans.end());
    for(i=0;i<n;i++){
        printf("%d\n",ans[i].second);
    }
}


Measured memory_bytes: 5488
import Foundation

#if swift(>=4.0)
extension String {
    func split(by separator: String) -> [String] {
        return self.components(separatedBy: separator)
    }
    func toArray() -> [String] {
        return self.map{String($0)}
    }
}
func exponentiate(_ lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#else
extension String {
    func split(by separator: String) -> [String] {
        return self.componentsSeparatedByString(separator)
    }
    var count: Int {
        return self.characters.count
    }
    func toArray() -> [String] {
        return self.characters.map{String($0)}
    }
    func uppercased() -> String {
        return self.uppercaseString
    }
    func lowercased() -> String {
        return self.lowercaseString
    }
}
//extension Array where Element == String {
//    func joined(separator separator: String) -> String {
//        return self.joinWithSeparator(separator)
//    }
//}
extension Array where Element: Comparable {
    func max() -> Element {
        return self.maxElement()!
    }
    func min() -> Element {
        return self.minElement()!
    }
    func sorted() -> Array {
        return self.sort()
    }
    func reversed() -> Array {
        return self.reverse()
    }
    mutating func sort() {
        self.sortInPlace()
    }
}
extension Array {
    init(repeating: Element, count: Int) {
        self.init(count: count, repeatedValue: repeating)
    }
}
func stride<T: Strideable>(from start: T, to end: T, by stride: T.Stride) -> StrideTo<T> {
    return start.stride(to: end, by: stride)
}
func exponentiate(lhs: Int, _ rhs: Int) -> Int {
    return (0..<rhs).reduce(1){i,_ in i*lhs}
}
#endif
func readInt() -> Int? {
    return Int(readLine()!)
}
func readStringSplit(by separator: String) -> [String] {
    return readLine()!.split(by: separator)
}
func readIntSplit(by separator: String) -> [Int] {
    return readLine()!.split(by: separator).map{Int($0)!}
}

/*************** テストスペース ***************/



/*************** メインプログラム ***************/

let input = readIntSplit(by: " ")
let (N, M) = (input[0], input[1])
var road = [Int](repeating: 0, count: N)
for _ in 0..<M {
    let input = readIntSplit(by: " ")
    let (a, b) = (input[0], input[1])
    road[a-1] += 1
    road[b-1] += 1
}
for i in road {
    print(i)
}


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

#define INF 1<<30
enum{Y, X};

int main() {
    int scene[100][100], picture[4][50][50], first[4][2], ans[2];
    int n, m;
    while(cin>>n>>m, n|m) {
        for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin>>scene[i][j];
        for(int i=0; i<m; i++) for(int j=0; j<m; j++) cin>>picture[0][i][j];
        for(int r=1; r<4; r++) for(int i=0; i<m; i++) for(int j=0; j<m; j++) picture[r][i][j] = picture[r-1][m-j-1][i];
        for(int r=0; r<4; r++) {
            bool found = false;
            for(int i=0; !found && i<m; i++) for(int j=0; !found && j<m; j++) {
                if(picture[r][i][j] == -1) continue;
                first[r][Y] = i;
                first[r][X] = j;
                found = true;
            }
        }
        ans[Y] = ans[X] = INF;
        for(int i=0; i<n-m+1; i++) for(int j=0; j<n-m+1; j++) {
            for(int r=0; r<4; r++) {
                bool ok = true;
                for(int y=0; ok && y<m; y++) for(int x=0; ok && x<m; x++) {
                    if(picture[r][y][x] == -1) continue;
                    if(scene[i+y][j+x] == picture[r][y][x]) continue;
                    ok = false;
                }
                if(ok) {
                    int y = i + first[r][Y] + 1, x = j + first[r][X] + 1;
                    if((y < ans[Y]) || (y == ans[Y] && x < ans[X])) {
                        ans[Y] = y;
                        ans[X] = x;
                    }
                }
            }
        }
        if(ans[Y]==INF) cout<<"NA"<<endl;
        else cout<<ans[X]<<" "<<ans[Y]<<endl;
    }
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}

struct Edge {
    ll from;
    ll to;
    ll cost;
};

using Edges = vector<Edge>;
const ll INF = 1LL << 60;

void bellman_ford(const Edges &Es, int V, int s, vector<ll> &dist) {
    dist.resize(V,INF);
    dist[0] = 0;
    int cnt = 0;
    while(cnt < 3*V) {
        for(auto e : Es) {
            if(dist[e.from] == INF) continue;
            if(dist[e.to] > dist[e.from] + e.cost) {
                dist[e.to] = dist[e.from] + e.cost;
                if(cnt == V-1) dist[e.to] = -INF;
            };
        }
        cnt++;
    }
}


int main()
{
    int n,m;
    cin >> n >> m;
    Edges Es(m);
    rep(i,m) {
        cin >> Es[i].from >> Es[i].to >> Es[i].cost;
        Es[i].from--; Es[i].to--;
        Es[i].cost *= -1;
    }

    vector<ll> dist;
    bellman_ford(Es, n, 0, dist);
    if(dist[n-1] < -INF) cout << "inf" << endl;
    else cout << -dist[n-1] << endl;
    return 0;
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N, Q, M;
    while (cin >> N >> Q, N | Q) {
        vi date(101);
        REP(i, N) {
            cin >> M;
            REP(j, M) {
                int a;
                cin >> a;
                date[a]++;
            }
        }
        pii ma = {0, 0};
        REP(i, 101) {
            if (date[i] >= Q) {
                ma = max(ma, {date[i], -i});
            }
        }
        cout << -ma.second << endl;
    }
}

Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"
#define F(n) for(ll i=0;i<n;i++)
#define Fab(a,b) for(ll i=a;i<b;i++)
//*max_element(a, a + n)
//cin.ignore(numeric_limits<streamsize>::max(), '\n');


ll t,n;


int main() {
    
ios_base::sync_with_stdio(false);
    cin.tie(NULL);

#ifdef _DEBUG
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    
    string s;ll flag=1;
    cin>>s;
    F(s.length()){
        if(s[i]=='7'){
            cout<<"Yes"; flag=0;
            break;
        }
    }
    if(flag)
    cout<<"No";
    return 0;
}
  



Measured memory_bytes: 3652
#!/usr/bin python3
# -*- coding: utf-8 -*-

# 双方向グラフで幅優先探索

from collections import deque

n, m = map(int, input().split())
g = [set([]) for _ in range(n)]
#隣接リストの作成
for i in range(m):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    g[a].add(b)

s, t = map(int, input().split())
s, t = s-1, t-1

#幅優先探索
q = deque()
level = [[-1]*n for i in range(3)]
q.append((s, 0))
level[0][s] = 0
while len(q)>0:
    cur, hp = q.popleft()
    lvl = level[hp][cur]
    for i in g[cur]:
        if level[(hp+1)%3][i]==-1:
            #階層
            level[(hp+1)%3][i] = lvl + 1
            q.append((i, (hp+1)%3))
print(level[0][t]//3)


Measured memory_bytes: 47284
num = int(input())
allNum = list(map(int, input().split()))

def down(allNum: list, count: int):
    if len(list(filter(lambda n: n % 2 != 0, allNum))) >= 1: return count
    count += 1
    allNum = list(map(lambda x: x / 2, allNum))
    return down(allNum, count)

print(down(allNum, 0))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;
#define int long long

int a[200000];
signed main() {
	int n, t; scanf("%lld%lld", &n, &t);
	int sum = 0;
	rep(i, n) {scanf("%lld", &a[i]);

	}
	rep(i, n-1) {
		sum += min(t, a[i + 1] - a[i]);
	}
	sum += t;
	printf("%lld\n", sum);
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;

int main()
{
	string s, t;
	cin>>s;
	cin>>t;
	int n=s.size();
	string u;
	bool ok=0;
	if(s==t) ok=1;
	for(int i=0; i<n; i++){
		string u;
		for(int j=i+1; j<n; j++){
			u+=s[j];
		}
		for(int j=0; j<=i; j++){
			u+=s[j];
		}
		if(u==t) ok=1;
	}
	if(ok){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
using namespace std;
#define X first
#define Y second
typedef long long LL;
typedef pair<int, int> pii;
const int N = 2e3 + 100;

int a[N];
int dp[N][2];
int main() {
    int n, Z, W;
    cin >> n >> Z >> W;
    for(int i = 1;i <= n; i ++) cin >> a[i];
    for(int i = n; i >= 2; i --) {
        dp[i][0] = abs(a[i - 1] - a[n]);
        dp[i][1] = abs(a[i - 1] - a[n]);
        for(int j = i + 1; j <= n; j ++) {
            dp[i][0] = max(dp[i][0], dp[j][1]);
            dp[i][1] = min(dp[i][1], dp[j][0]);
        }
    }
    int ans = abs(a[n] - W);
    for(int i = 2; i <= n; i ++) ans = max(ans, dp[i][1]);
    printf("%d\n", ans);
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int set = sc.nextInt();

		while(set-- > 0){
			int n=sc.nextInt(), m=sc.nextInt();

			int[] t = new int[n];
			int[] s = new int[m];
			for(int i=0;i<n;i++) t[i] = toNum(sc.next());
			for(int i=0;i<m;i++) s[i] = toNum(sc.next());

			System.out.println(solve(t,s,n-1) || solve(t,s,n-2) ?
												 "Yes" : "No");
		}
	}

	private static int toNum(String s){
		if(s.equals("C"))  return 0;
		if(s.equals("C#")) return 1;
		if(s.equals("D"))  return 2;
		if(s.equals("D#")) return 3;
		if(s.equals("E"))  return 4;
		if(s.equals("F"))  return 5;
		if(s.equals("F#")) return 6;
		if(s.equals("G"))  return 7;
		if(s.equals("G#")) return 8;
		if(s.equals("A"))  return 9;
		if(s.equals("A#")) return 10;
		if(s.equals("B"))  return 11;
		return -1;
	}

	private static boolean solve(int[] t,int[] s,int index){
		int i = index;

		for(int j=s.length-1;j>=0;j--){
			if(i < 0 || t.length <= i) return false;
			i += nexts(t[i],s[j]);
		}
		if(i == -1) return true;
		return false;
	}

	private static int nexts(int t,int s){
		if(t == s) return -1;
		if(bound(t-1) == s) return 1;
		if(bound(t+1) == s) return -2;
		return 500000;
	}

	private static int bound(int index){
		return (index + 12) % 12;
	}
}

Measured memory_bytes: 15000
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define REP(i, n) for(int i=0; i<=n; i++)
#define repr(i, n) for(int i=n; i>0; i--)
#define REPR(i, n) for(int i=n; i>=0; i--)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
template<class T> void puts(T x) { std::cout << x << std::endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int MAX_N = 110;
const int MAX_V = 100010;
int N, W;
ll w[MAX_N], v[MAX_N];
ll dp[MAX_N][MAX_V];


int main() {
    cin >> N >> W;
    rep(i, N) cin >> w[i] >> v[i];

    rep(i, MAX_N) { rep(j, MAX_V) dp[i][j] = LLINF; }
    dp[0][0] = 0;

    for (int i = 0; i < N; i++) {
        for (int sum_v = 0; sum_v < MAX_V; sum_v++) {
            if (sum_v - v[i] >= 0) {
                chmin(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    int ans = 0;
    for (int sum_v = 0; sum_v <= MAX_V; sum_v++) {
        if (dp[N][sum_v] <= W) ans = sum_v;
    }
    cout << ans << endl;
}


Measured memory_bytes: 86784
#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>;

const ll INF = 1e18;
const int MX = 2005;

int main() {
  int n;
  cin >> n;
  set<string>st;
  rep(i,n){
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}

Measured memory_bytes: 19212