akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main{

	public static long solve(long x,long y){
		long menseki = x * y;
		long s1 = menseki;
		long s2 = 0;
		long s3 = 0;
		long result = 0;
		for(int i = 0;i < x;i++){
			s1 = (x - i) * y;
			s2 = i * (y/2);
			s3 = menseki - s1 - s2;
			long smax = Math.max(s1,s2);
			smax = Math.max(s3,smax);
			long smin = Math.min(s1,s2);
			smin = Math.min(s3,smin);
			if(i == 0){
				result = smax - smin;
			}else{
				result = Math.min(result,smax - smin);
			}
			s2 = (i/2) * y;
			s3 = menseki - s1 - s2;
			smax = Math.max(s1,s2);
			smax = Math.max(s3,smax);
			smin = Math.min(s1,s2);
			smin = Math.min(s3,smin);
			result = Math.min(result,smax - smin);			
		}
		for(int i = 0;i < y;i++){
			s1 = x * (y - i);
			s2 = (x/2) * i;
			s3 = menseki - s1 - s2;
			long smax = Math.max(s1,s2);
			smax = Math.max(s3,smax);
			long smin = Math.min(s1,s2);
			smin = Math.min(s3,smin);
			result = Math.min(result,smax - smin);
			s2 = x * (i/2);
			s3 = menseki - s1 - s2;
			smax = Math.max(s1,s2);
			smax = Math.max(s3,smax);
			smin = Math.min(s1,s2);
			smin = Math.min(s3,smin);
			result = Math.min(result,smax - smin);
		}
		return result;

	}

	public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] input = br.readLine().split(" ");
        long x = Long.parseLong(input[0]);
        long y = Long.parseLong(input[1]);
        System.out.println(solve(x,y));

    }

}

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

a = []
maximum = 0
second_maximum = 0
for i in range(n):
    input_num = int(input())
    a.append(input_num)
    if input_num > maximum:
        second_maximum = maximum
        maximum = input_num
    elif input_num > second_maximum:
        second_maximum = input_num
        
for a_num in a:
    if a_num == maximum:
        print(second_maximum)
    else:
        print(maximum)

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

int main()
{
    int N, L;
    cin >> N >> L;
    int min = 1000;
    int taste_all = 0;
    for(int i = 0; i < N; i++){
      taste_all += L + i;
      if(abs(L + i) < abs(min)){
        min = L + i;
      }
    }
    cout << taste_all - min << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
n, h, *d = map(int, open(0).read().split())
a = max(d[::2])
b = sorted(b for b in d[1::2] if b >= a)[::-1]
i = 0
for b in b:
    h -= b
    i += 1
    if h <= 0:
        print(i)
        exit()
print(i + 0--h // a)

Measured memory_bytes: 25124
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <math.h>
#include <numeric>
#define rep(i,s,n) for (int i = s; i < n; ++i)
#define drep(i,s,n) for (int i = n; i >= s; --i)
#define all(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define print(x) cout<<(x)<<endl
using namespace std;
typedef long long ll;

int gcd(int a, int b)
{
   if (a%b == 0) return(b);
   else          return(gcd(b, a%b));
}
int lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
void printvv(vector<vector<auto>> vv, int n)
{
  cout << '[' << endl;
  rep(q, 0, n)
  {
    cout << '[';
    rep(p, 0, n)
    {
      cout << vv.at(q).at(p) << ',';
    }
    cout << ']' << endl;
  }
  cout << ']' << endl;
}

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

//------------------------------------------------------------
void solve() {
  int N, a,b;
  cin >> N >> a >> b;

  if ((b-a-1)%2==0) print("Borys");
  else print("Alice");

  return;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#define rg register
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) ((a)>0?(a):-(a))
#define ll long long 
#define maxn 50000
#pragma GCC optimize(3)
#pragma -fcrossjumping
#pragma -fdefer-pop
#pragma -fmerge-constans
#pragma -fthread-jumps
#pragma -floop-optimize
#pragma -fif-conversion
#pragma -fif-conversion2
#pragma -fdelayed-branch
#pragma -fguess-branch-probability
#pragma -fcprop-registers
#pragma -fforce-mem
#pragma -foptimize-sibling-calls
#pragma -fstrength-reduce
#pragma -fgcse
#pragma -fcse-follow-jumps
#pragma -frerun-cse-after-loop
#pragma -fdelete-null-pointer-checks
#pragma -fextensive-optimizations
#pragma -fregmove
#pragma -fschedule-insns
#pragma -fsched-interblock
#pragma -fcaller-saves
#pragma -fpeephole2
#pragma -freorder-blocks
#pragma -fstrict-aliasing
#pragma -funit-at-a-time
#pragma -falign-functions
#pragma -fcrossjumping
#pragma -finline-functions
#pragma -fweb
using namespace std;
inline ll read()
{
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9')
	{
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0')
	{
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}
ll n;
struct node
{
	ll a;
	ll id;
}s[maxn];
inline bool cmp(node a,node b)
{
	return a.a<b.a;
}
int main()
{
	int tot=0;
	n=read();
	for(rg int i=1;i<=n;++i)
	{
		s[i].a=read();
		s[i].id=i;
	}
	sort(s+1,s+1+n,cmp);
	for(rg int i=1;i<=n;++i)
	{
		if(s[i].id!=i) ++tot;
	}
	if(tot==1||tot>2)
	{
		cout<<"NO";
	} 
	else
	{
		cout<<"YES";
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        for (int i = 0; i < n; i++) {
            int a = sc.nextInt();
            ans += solve(a);
        }

        sc.close();

        System.out.println(ans);
    }

    private static int solve(int num) {
        if (num % 2 != 0) {
            return 0;
        } else {
            return solve(num / 2) + 1;
        }
    }
}

Measured memory_bytes: 34308
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("faild to read char") as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    token
        .parse()
        .ok()
        .expect("faild to parse token")
}

fn main(){
    let n: i32 = read();
    let k: i32 = read();
    println!("{}", n - k + 1);
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if(a == 1) a = 14;
        int b = sc.nextInt();
        if(b == 1) b = 14;
        if(a > b) System.out.println("Alice");
        else if(a < b) System.out.println("Bob");
        else System.out.println("Draw");
    }
}

Measured memory_bytes: 35612
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	static class FastReader
	{
		BufferedReader br;
		StringTokenizer st;

		public FastReader()
		{
			br = new BufferedReader(new
					InputStreamReader(System.in));
		}

		String next()
		{
			while (st == null || !st.hasMoreElements())
			{
				try
				{
					st = new StringTokenizer(br.readLine());
				}
				catch (IOException  e)
				{
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

		long nextLong()
		{
			return Long.parseLong(next());
		}

		double nextDouble()
		{
			return Double.parseDouble(next());
		}

		String nextLine()
		{
			String str = "";
			try
			{
				str = br.readLine();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
			return str;
		}
	}
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		FastReader sc = new FastReader();
		int N = sc.nextInt(), W = sc.nextInt();
		int[] w = new int[N], v = new int[N];
		for (int i=0; i<N; i++) {
			w[i] = sc.nextInt(); 
			v[i] = sc.nextInt(); 
		}
		long[] dp = new long[200010]; 
		Arrays.fill(dp, 1L<<60);

		int max = 0; 
		dp[0] = 0; 
		for (int i=0; i<N; i++) {
			for (int j=200000; j>=v[i]; j--) {
				if (dp[j-v[i]] + w[i]<=W && dp[j-v[i]]>=0) {
					dp[j] = Math.min(dp[j], dp[j-v[i]] + w[i]); 
					max = Math.max(j, max); 
				}
			}
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 27220
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>

//#define int long long

using namespace std;

void Main()
{
	string S;
	cin >> S;
	for (int i = 0; i < 4; i++) {
		int num = 0;
		for (int k = 0; k < 4; k++) {
			if (S[i] == S[k]) {
				num++;
			}
		}
		if (num != 2) {
			cout << "No" << endl;
			return;
		}
	}
	cout << "Yes" << endl;
}

int32_t main()
{
	Main();
	return 0;
}

/*
void sample()
{
	vector<int> v;
	sort(v.begin(), v.end());
	sort(v.begin(), v.end(), greater<int>());

}
*/



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

vector<double> A;

// 長さaの丸太をX以下の長さにするには何回切るか？
int cut(double a, double X) {
    int ret;

    // if (a <= X) {
    //     ret = 0;
    // } else {
    //     ret = (int)ceil(a / X);
    // }

    ret = (int)floor(a / X - 0.000000000000001);

    return ret;
}

// 長さX以下にするには何回切るか？
int C(double X) {
    int ret = 0;

    for (auto a : A) {
        ret += cut(a, X);
    }

    return ret;
}


int main() {
    int N, K;
    cin >> N >> K;
    // vector<double> A(N);
    A.resize(N);
    rep(i, N) cin >> A[i];

    double left = 0.0;  // できないギリギリ
    double right = 1e9 + 1;  // できるギリギリ

    // cout << C(1.0) << endl;
    // cout << C(2.0) << endl;
    // cout << C(3.0) << endl;
    // cout << C(5.0) << endl;

    // cout << cut(10.0, 3.0) << endl;
    // cout << cut(6.0, 3.0) << endl;
    // cout << cut(6.0, 1.0) << endl;
    // cout << cut(6.0, 0.99) << endl;

    int count = 100;
    while (count--) {
        double mid = (left + right) / 2.0;

        if (C(mid) <= K) {
            right = mid;
        } else {
            left = mid;
        }
    }

    // cout << std::fixed << std::setprecision(20) << right << endl;

    cout << (int)ceil(right - 0.000000000000001) << endl;
    // cout << (int)right << endl;
}

Measured memory_bytes: 4716
using System;

namespace AtCoder0106_3
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int y = int.Parse(input[1]);
            string result = String.Empty;

            if (n * 1000 > y || n * 10000 < y)
            {
                result = "-1 -1 -1";
            }
            else
            {
                int tmp = y / 1000 - n;

                for (int i = 0; i <= tmp; i++)
                {
                    if ((tmp - 9 * i) % 4 == 0)
                    {
                        int tmpresult = (tmp - 9 * i) / 4;
                        if (tmpresult >= 0 && n - i - tmpresult >= 0)
                        {
                            result = i.ToString() + " " + tmpresult.ToString() + " " + (n - i - tmpresult).ToString();
                            break;
                        }
                    }
                }
            }
            if (result == String.Empty)
            {
                result = "-1 -1 -1";
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 11092
fun main(args: Array<String>) {
    arc095b()
}

fun arc095b() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(" ").map { it.toLong() }.toMutableList()

    val max = a.max()!!
    a.remove(max)
    val mid = a.minBy { Math.abs(it * 2 - max) }!!

    val answer = "$max $mid"

    println(answer)
}



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

int main() {
  /* code */
  int N;
  cin >> N;
  int i, j;
  int cnt;
  int cnt_8 = 0;
  for(i = 1; i <= N; i += 2)
  {
    cnt = 0;
      for(j = 1; j <= i; j++) //約数探索
      {
        if(i % j == 0)
        {
          cnt++;
        }
      }
      if(cnt == 8)  //約数が8個であればインクリメント
      {
        cnt_8++;
      }
    }
  cout << cnt_8 << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0
prev = -2
for a in A:
    ans += B[a - 1]
    if a == prev + 1:
        ans += C[prev - 1]
    prev = a

print(ans)
    


Measured memory_bytes: 3060
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,*A = map(int, read().split())

    if 0 in A:
        print(0)
        exit()

    INF = 10**18
    ans = 1
    for a in A:
        ans *= a
        if ans > INF:
            print(-1)
            exit()
    
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 21772
import java.util.*;
public class Main {
	public static void main (String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
        int count = 0;

      while(n>0){
        if(n>=1&&n<=9){count++;}
        else if(n>=100&&n<=999){count++;}
        else if(n>=10000&&n<=99999){count++;}
        n--;
      }
      
      System.out.print(count);
      
	}
}


Measured memory_bytes: 21332
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define sz(s) ((int) ((s).size()))

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

typedef long long ll;
typedef long double ld;

const int inf = (int) 1.01e9;
const ld eps = 1e-11;
const ld pi = acos(-1.0L);

mt19937 mrand(random_device{} ());
int rnd(int x) {
  return mrand() % x;
}

const int mod = (int) 1e9 + 7;

void add(int & x, int y) {
  if ((x += y) >= mod) {
    x -= mod;
  }
}

int sum(int x, int y) {
  add(x, y);
  return x;
}

int mult(int x, int y) {
  return (ll) x * y % mod;
}

int power(int x, ll p) {
  int res = 1;
  while (p) {
    if (p & 1) {
      res = mult(res, x);
    }
    x = mult(x, x);
    p >>= 1;
  }
  return res;
}

int inv(int x) {
  return power(x, mod - 2);
}

void precalc() {
}

const int maxn = 1e5 + 100;

int n;
int a[maxn];

bool read() {
  if (scanf("%d", &n) < 1) {
    return false;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", a + i);
  }
  return true;
}

void solve() {
  int res = 1;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    cnt++;
    if (cnt * 2 - 1 > a[i]) {
      res = mult(res, cnt);
      cnt--;
    }
  }
  for (int i = 1; i <= cnt; i++) {
    res = mult(res, i);
  }
  printf("%d\n", res);
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen("text.in", "r", stdin));
  assert(freopen("text.out", "w", stdout));
#endif

  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time: %.3f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}



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

int main() {

ll a,b,c,k,ans;
cin>>a>>b>>c>>k;
ans=min(a,k);
k-=min(a,k);
k-=min(b,k);
ans-=min(c,k);
cout<<ans<<endl;

return 0;
}
/*vector <int> a(3);
for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }*/

Measured memory_bytes: 3592
def solve():
    A, B, C, K = map(int, input().split())
    if A >= K >= 1:
        print('{}'.format(K))
    elif A + B >= K > A:
        print('{}'.format(A))
    elif A + B + C >= K > A + B:
        result = 2 * A + B - K
        print('{}'.format(result))

        return


if __name__ == "__main__":
    solve()

Measured memory_bytes: 9192
package main

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

var sc *bufio.Scanner

func main() {
    sc = initScanner(os.Stdin)
    fmt.Println(resolve(parseProblem()))
}

func parseProblem() (int, int, int, []int, []int) {
    n := scanInt(sc)
    m := scanInt(sc)
    k := scanInt(sc)
    a := make([]int, n)
    b := make([]int, m)
    for i := 0; i < n; i++ {
        a[i] = scanInt(sc)
    }
    for i := 0; i < m; i++ {
        b[i] = scanInt(sc)
    }
    return n, m, k, a, b
}

func resolve(n, m, k int, a, b []int) int {
    suma := sum_slice(a)
    sumb := sum_slice(b)
    ans := 0
    t := m
    // aを0冊から試す
    for i := 0; i <= n; i++ {
        // bをt冊から試す
        for j := t; j >= 0; j-- {
            if suma[i] + sumb[j] <= k {
                ans = max(ans, i + j)
                t = j
                break
            }
        }
        if suma[i] > k {
            break
        }
    }
    return ans
}

func sum_slice(n []int) []int {
    sum := make([]int, len(n)+1)
    sum[0] = 0
    for i:=0; i<len(n); i++ {
        sum[i+1] = sum[i] + n[i]
    }
    return sum
}


func max(a, b int) int {
    if a >= b {
        return a
    }
    return b
}

func initScanner(r io.Reader) *bufio.Scanner {
    sc := bufio.NewScanner(r)
    sc.Split(bufio.ScanWords)
    return sc
}

func scanInt(sc *bufio.Scanner) int {
    sc.Scan()
    i, _ := strconv.Atoi(sc.Text())
    return int(i)
}

func scanString(sc *bufio.Scanner) string {
    sc.Scan()
    return sc.Text()
}



Measured memory_bytes: 9968
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<map>
#include<algorithm>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;

    if (A == 2) {
        cout << "No" << endl;
        return 0;
    }
    if (B == 2) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
#define y1 y11111

double x1,y1,x2,y2;
int main(){
	scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
	x2-=x1;
	y2-=y1;
	double len=hypot(x2,y2);
	x2/=len;
	y2/=len;
	int q;
	scanf("%d",&q);
	while(q--){
		double x,y;
		scanf("%lf%lf",&x,&y);
		x-=x1;
		y-=y1;
		double r=(x*x2+y*y2);
		printf("%.9f %.9f\n",x1+2*r*x2-x,y1+2*r*y2-y);
	}
}


Measured memory_bytes: 2112
#include <iostream>
#include <complex>
#include <vector>
#include <cmath>
using namespace std;
typedef complex<double> P;

double area(vector<P> &p){
	double ans = 0;
	for(int i = 0 ; i+1 < p.size() ; i++)
		ans += p[i].real() * p[i+1].imag() - p[i].imag() * p[i+1].real() ; 
	
	return abs(ans) / 2.0;
}
double tri2(P a,P b, P c){
	a -= c;
	b -= c;
	return abs( a.real() * b.imag() - b.real() * a.imag() );
}

bool in(vector<P> &p,P c){
	p.push_back(p[0]);
	double a = area(p) , b = 0;
	for(int i = 0 ; i+1 < p.size() ; i++){
		b += tri2(p[i],p[i+1],c);
	}
	b = abs(b)/2;
	
	p.pop_back();
	return fabs(a - b) < 1e-9;
}

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

bool on_seg(P p1,P p2,P q){
	return abs( det(p1-q,p2-q) ) < 1e-9 && dot((p1-q),(p2-q)) <= 1e-9;
}


P intersection(P p1,P p2,P q1,P q2){
	return p1 + (p2-p1)*( det(q2-q1,q1-p1) / ( det(q2-q1,p2-p1) ) );
}

bool chk(P p1,P p2,P q1,P q2){
	if( abs( det(p2 - p1 , q2 -q1 ) ) < 1e-9 ){
		return on_seg(p2,p1,q2) || on_seg(p2,p1,q1) || on_seg(q1,q2,p1) || on_seg(q1,q2,p2);
	}else{
		P r = intersection(p2,p1,q2,q1);
		return on_seg(p2,p1,r) && on_seg(q2,q1,r);
	}
}

int done[100] = {};
int M;
int dfs(int pos,bool connect[100][100]){
	if( done[pos] ) return 0;
	else done[pos] = true;
	for(int i = 0 ; i < M ; i++){
		if( connect[pos][i] ) dfs(i,connect);
	}
}
int main(){
	int N;
	while(cin >> N && N){
		for(int i = 0 ; i < N ; i++){
			cin >> M;
			vector<P> p[100];
			for(int j = 0 ; j < M ; j++){
				for(int k = 0 ; k < 4 ; k++){
					P a;
					cin >> a.real() >> a.imag();
					p[j].push_back(a);
				}
			}
			bool connect[100][100] = {};
			for(int j = 0 ; j < M ; j++)
				for(int k = 0 ; k < M ; k++){
					for(int l = 0 ; l < 4 ; l++){
						if( in(p[j],p[k][l]) ){
							connect[j][k] = connect[k][j] = true;
						}
					}
				}
			for(int j = 0 ; j < M ; j++)
				for(int k = 0 ; k < M ; k++){
					for(int l = 0 ; l < 4 ; l++){
						for(int m = 0 ; m < 4 ; m++){
							if( chk(p[j][l],p[j][(l+1)%4],p[k][m],p[k][(m+1)%4]) ){
								connect[j][k] = connect[k][j] = true;
							}
						}
					}
				}
			for(int i = 0 ; i < 100 ; i++){
				done[i] = 0;
			}
			int ans = 0;
			for(int i = 0 ; i < M ; i++){
				if(done[i] == 0){
					dfs(i,connect);
					ans++;
				}
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 992
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int H=sc.nextInt(),W=sc.nextInt(),N=sc.nextInt();
		int sum = 0;
		if(H>=W) {
			for(int i=1;i<=W;i++) {
				if(H*i>=N) {
					sum = i;
					break;
				}
			}
		}else {
			for(int i=1;i<=H;i++)
				if(W*i>=N) {
					sum = i;
					break;
				}
		}
		System.out.print(sum);
	}
}


Measured memory_bytes: 23764
#include<iostream>
#include<vector>
using namespace std ;
using ll = long long int ;

ll min(ll a,ll b){
    if(a<=b) return a ;
    else return b ;
}

ll sa(ll a,ll b){
	if(a>=b) return a-b ;
	else return b-a ;
}

int main(){
	int n ; cin >> n ;
	int k ; cin >> k ;
	vector<ll> h(n) ;
	for(int i=0;i<n;i++) cin >> h.at(i) ;
	vector<ll> c(n,100000000000) ;
	c.at(0) = 0 ;
	for(int i=1;i<n;i++){
		for(int j=1;j<=min(i,k);j++){
			c.at(i) = min(c.at(i),c.at(i-j)+sa(h.at(i),h.at(i-j))) ;

		}
	}
	cout << c.at(n-1) << endl ;
}


Measured memory_bytes: 1792
//region trash
#ifndef LOCAL
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#define DB(x){if(cond)cerr<<__LINE__<<" "<<#x<<" " <<x<<endl;}
#else
#define DB(x){}
#endif
#define REP(i,b)for(auto i=0;i<(b);++i)
#define FOR(i,a,b)for(auto i=(a);i<=(b);++i)
#define FORD(i,a,b)for(auto i=(a);i>=(b);--i)
#define FORDE(rit,x)for(auto rit=(x).rbegin();rit!=(x).rend();rit++)
#define VV vector
#define PB push_back
#define ALL(x) (x).begin(),(x).end()
template<typename X, typename Y>bool MA(X&a,Y b){if(a<b){a=b;return true;} return false;}
template<typename X, typename Y>bool MI(X&a,Y b){if(a>b){a=b;return true;} return false;}
typedef long long LL,ll;typedef long double LD,ld;
typedef array<int,2>I2,i2;typedef VV<int>VI,vi;
using namespace std;
int cond=0;
//endregion

int mode=0;

int H, W;

char A[1111][1111];
int DST[1111][1111];
#define I2 array<int,2>

struct Solver {
  void solve() {
    cin>>H>>W;
    REP(h,H)cin>>A[h];


    queue<I2> Q;
    REP(r,H)REP(c,W) {
      if(A[r][c] != '#') continue;

      DST[r][c] = 1;
      Q.push({r,c});
    }
    while(!Q.empty()) {
      auto top = Q.front();
      DB(top[0]<<" "<<top[1]);
      Q.pop();
      FOR(dr,-1,1)FOR(dc,-1,1)if(abs(dr) + abs(dc) == 1) {
        int nr=top[0] +dr, nc=top[1] + dc;
        if (nr >= 0 && nr < H && nc >= 0 && nc < W) {
          if (DST[nr][nc]) continue;
          DST[nr][nc] = DST[top[0]][top[1]] + 1;
          Q.push({nr,nc});
        }
      }
    }
    int res = 0;
    REP(r,H)REP(c,W) res=max(res, DST[r][c]);
    cout<<res-1<<endl;
  }
};


int main(int argc,char** argv){
  struct Solver2 {
    void gen() {}
    void brute() {}
  };
  random_device rd{};
  uint64_t seed = (uint64_t)rd()
      ^ (uint64_t)std::chrono::steady_clock::now().time_since_epoch().count()
      ^ (uint64_t)__builtin_ia32_rdtsc()
      ^ (uint64_t)make_unique<char>().get();
  srand(seed); mt19937 rng(seed);

  ios::sync_with_stdio(false),cin.tie(nullptr);
  FOR(a,1,argc-1){if(argv[a][0]=='g') { Solver2 solver; solver.gen(); return 0; }}
  FOR(a,1,argc-1){if(argv[a][0]=='q') cond=1U<<30U;}
  cout.setf(ios::fixed),cout.precision(10);
  int t{};if(mode >= 1)cin>>t;else t=1;
  bool isBrute=false;FOR(a,1,argc-1)if(argv[a][0]=='b')isBrute=true;
  FOR(i,1,t){if(cond)cerr<<__LINE__<<" "<<i<<endl;if(mode == 2)cout<<"Case #"<<i<<": ";
    auto solver = make_unique<Solver>();
    auto solver2 = make_unique<Solver2>();
    if (isBrute)
      solver2->brute();
    else
      solver->solve();
  }
  return 0;
}


Measured memory_bytes: 13968
"""
author : halo2halo
date : 16, Jan, 2020
"""

import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N = int(readline())
L = list(map(int, readline().split()))
Lm=max(L)
S = sum(L)
ans = True

print('Yes' if S>2*Lm else 'No')



Measured memory_bytes: 12508
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(void){
    cin.tie(0);
    int n, h, p, q;
    cin>>n>>h;
    vector<int> a, b;
    for(int i = 0; i < n; i++){
        cin>>p>>q;
        a.push_back(p);
        b.push_back(q);
    }
    sort(b.begin(), b.end(), greater<int>());
    sort(a.begin(), a.end(), greater<int>());
    int m = a[0];
    int ans=0;
    while(h>0 && b.size() != 0){
      if(b[0]<m)
        break;
      h-=b[0];
      b.erase(b.begin());
      ans+=1;        
    }
    if(h>0)
  	  if(h%m == 0)
		ans+=h/m;
      else
        ans+=h/m+1;
//        ans+=ceil(h/m);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1276
using System;
using System.Linq;
using System.Collections.Generic;

class Mondai
{
    static void Main()
    {
        var input = Console.ReadLine().Split(' ').Select(x => Int32.Parse(x)).ToArray();
        var a = (input[0] * 3 + input[1]) / 2;
        Console.WriteLine(a);
    }
}

Measured memory_bytes: 13268
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n;i>0;i--)
#define rep1(i,s,n) for(int i=s;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c) 
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;

int main(){
   int n;
   cin>>n;
   plvec p(n);
   rep(i,n){
      ll a,b;
      cin>>a>>b;
      p[i]=make_pair(b,a);
   }
   sort(p.begin(),p.end());
   bool flag=true;
   ll count=0;
   rep(i,n){
      count+=p[i].second;
      if(count>p[i].first){
         flag=false;
         break;
      }
   }
   if(flag) cout<<"Yes";
   else cout<<"No";
}


Measured memory_bytes: 3328
import std.stdio, std.algorithm, std.string, std.conv, std.array, std.range, std.math;
int readint() { return readln.chomp.to!int; }
int[] readints() { return readln.split.to!(int[]); }

void main() {
    int x = readint();

    int ans = 1;
    foreach (b; 2..1000) {
        for (int p = 2; b^^p <= x; p++) {
            int y = b^^p;
            if (y > ans) ans = y;
        }
    }
    writeln(ans);
    string _ = readln;
}

Measured memory_bytes: 256
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

#define rep(i, c) for(int i = 0; i < int(c); i++)
#define ALL(obj) (obj).begin(), (obj).end() //sort(ALL(obj))みたいな



using namespace std;

int main() {
  string s;
  cin >> s;
  rep(i, s.size()) cout << "x";
  cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    string s;
    cin>>n>>s;
    for(int i=0;i<s.size();i++)
    {
        int temp = s[i];
        temp=(temp+n);
        if(temp>'Z')
        {
            temp=temp-'Z'+'A'-1;
        }
        //cout<<temp<<endl;
        s[i]=(char)temp;
    }
    cout<<s<<endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

int A, B;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cin >> A >> B;
	if (A > 9 || B > 9) cout << -1;
	else cout << A * B;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
int main() {
  ll a,b;
  cin >> a >> b;
  ll an = a/50+1;
  ll bn = b/50+1;
  cout << an*2 + bn*2 << " " << 100 << endl;
  a--;
  b--;
  REP(i,an){
    ll num = min(a,50ll);
    REP(j,50){
      if(j<num) cout << ".";
      else cout << "#";
      cout << "#";
    }
    cout << endl;
    REP(j,100) cout << "#";
    cout << endl;
    a -= num;
  }
  REP(i,bn){
    ll num = min(b,50ll);
    REP(j,100) cout << ".";
    cout << endl;
    REP(j,50){
      if(j<num) cout << "#";
      else cout << ".";
      cout << ".";
    }
    cout << endl;
    b -= num;
  }
  return 0;
}


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

int cnt = 0,g[500][500] = {0},n,m;
bool is_visited[500] = {false};

void dfs(int v,int d){
    if(d > 0 && !is_visited[v]) cnt++;
    if(d == 2) return;
    
    rep(i,1,n){
        if(g[v][i]){
            dfs(i,d+1);
            is_visited[i] = true;
        }
    }
    
    return;
}


int main(){
    int a,b;
    
    while(1){
        cin >> n >> m;
        if(n+m == 0) break;
        
        cnt = 0;
        
        rep(i,0,n){
            is_visited[i] = false;
            rep(j,0,n){
                g[i][j] = 0;
            }
        }
        rep(i,0,m){
            cin >> a >> b;
            g[a-1][b-1] = 1;
            g[b-1][a-1] = 1;
        }
        
        dfs(0,0);
        cout << cnt << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3948
import numpy as np
n=int(input())
v=list(map(int,input().split()))
v.sort()
ans=0
for i in range(1,n+1):
    if i<=2:
        ans+=v[i-1]/(2**(n-1))
    else:
        ans+=v[i-1]/(2**(n+1-i))
print(ans)

Measured memory_bytes: 12468
#include <bits/stdc++.h>
 
using namespace std;
#define pb push_back

typedef long long int ll;

struct ds{
	int a,b,c,d;
};

int a[505][505];
vector<ds> v;

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

	
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++) cin>>a[i][j];
	}

	for(int i=0;i<n-1;i++){
		for(int j=0;j<m;j++){
			if(a[j][i]%2){
				a[j][i]--; a[j][i+1]++;
				ds x; x.a=j+1; x.b=i+1; x.c=j+1; x.d=i+2; v.pb(x);
			}
		}
	}

	for(int i=0;i<m-1;i++){
		if(a[i][n-1]%2){
				a[i][n-1]--; a[i+1][n-1]++;
				ds x; x.a=i+1; x.b=n; x.c=i+2; x.d=n; v.pb(x);
			}
	}

	cout<<v.size()<<endl;
	for(auto p:v) {
		cout<<p.a<<" "<<p.b<<" "<<p.c<<" "<<p.d<<endl;
	}
}

Measured memory_bytes: 5232
import sys
from itertools import accumulate

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, W, *WV = map(int, read().split())
    weight = WV[::2]
    value = WV[1::2]

    w_min = min(weight)
    items = [[] for _ in range(4)]
    for w, v in zip(weight, value):
        items[w - w_min].append(v)

    for i in range(4):
        items[i].sort(reverse=True)

    csums = [0] * 4
    for i in range(4):
        csums[i] = [0]
        csums[i].extend(accumulate(items[i]))

    def rec(i, w, v):
        if i == 4:
            if w <= W:
                return v
            else:
                return -1
        ans = 0
        for j in range(len(csums[i])):
            ans = max(ans, rec(i + 1, w + (w_min + i) * j, v + csums[i][j]))

        return ans

    print(rec(0, 0, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9160
from collections import deque

n, x, y = map(int, input().split())

ans = [0] * n
for i in range(1, n + 1):
    seen = [-1] * (n + 1)
    seen[i] = 0
    q = deque()
    q.append(i)
    while len(q) > 0:
        v = q.popleft()
        ans[seen[v]] += 1
        nv = v - 1
        if nv >= 1 and seen[nv] == -1:
            q.append(nv)
            seen[nv] = seen[v] + 1
        nv = v + 1
        if nv <= n and seen[nv] == -1:
            q.append(nv)
            seen[nv] = seen[v] + 1
        if v == x and seen[y] == -1:
            q.append(y)
            seen[y] = seen[v] + 1
        if v == y and seen[x] == -1:
            q.append(x)
            seen[x] = seen[v] + 1
for v in ans[1:]:
    print(v // 2)


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

int main() {
  ll n;
  cin >> n;
  string s;
  cin >> s;
  vector<map<char,ll>> bit(5000010);
  for(ll i=0;i<n;i++) {
    for(ll x=i+1;x<=n;x+=x&-x) {
      bit[x][s[i]]++;
    }
  }
  ll q;
  cin >> q;
  vector<ll> c(q);
  vector<ll> p(q);
  vector<char> v(q);
  vector<ll> va(q);
  for(ll i=0;i<q;i++) {
    cin >> c[i] >> p[i];
    if(c[i]==1) {
      cin >> v[i];
    }
    else {
      cin >> va[i];
    }
  } 
  for(ll i=0;i<q;i++) {
    if(c[i]==1) {
      if(s[p[i]-1]!=v[i]) {
        for(ll x=p[i];x<=n;x+=x&-x) {
          bit[x][s[p[i]-1]]--;
        }
        s[p[i]-1]=v[i];
        for(ll x=p[i];x<=n;x+=x&-x) {
          bit[x][s[p[i]-1]]++;
        }
      }
    }
    else if(c[i]==2) {
      ll res=0;
      map<char,ll> out;
      for(char z='a';z<'z'+1;z++) {
        if(p[i]>1) {
          for(ll x=p[i]-1;x>0;x -= x & -x) {
            out[z]-=bit[x][z];
          }
        }
        for(ll x=va[i];x>0;x -= x & -x) {
          out[z]+=bit[x][z];
        }
        if(out[z]>0) {
          res++;
        }
      }
      cout << res << endl;
    }
  }
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<pair<long, long>> s;
    vector<pair<long, long>> p;
    for(int i = 0; i < n; i++)
    {
        long a, b;
        cin >> a >> b;
        s.push_back(pair<long, long>{a, b});
    }
    for(int i = 0; i < m; i++)
    {
        long c, d;
        cin >> c >> d;
        p.push_back(pair<long, long>{c, d});
    }
    
    for(auto&& x : s)
    {
        long min = 1e9;
        long index = -1;
        for(int i = m - 1; i >= 0; i--)
        {
            long d = abs(x.first - p[i].first) + abs(x.second - p[i].second);
            if (d <= min) {
                min = d;
                index = i + 1;
            }
        }
        cout << index << "\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define endl "\n"
#define int long long int
#define f(i, a, b) for(int i=a; i<b; i++)
#define fb(i, a, b) for(int i=a; i>=b; i--)
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define LB lower_bound
#define UB upper_bound
#define fp(x, y) fixed<<setprecision(y)<<x
#define PI 3.141592653589793238462643383279502884
using namespace std;

const int M = (int)2e5+5;
const int mod = (int)1e9+7;

int powM(int b, int p, int m)
{
    int ans = 1;
    while(p)
    {
        if(p%2LL) ans = (ans*b)%m;
        b = (b*b)%m;
        p /= 2LL;
    }
    return ans;
}

int cnt[M] = {0, 1};

void solve()
{
    int n, ans = 0, b = 0;
    string s;
    cin>>n>>s;
    int modinc = 0, moddec = 0;
    f(i, 2, M+1) cnt[i] = cnt[i%(__builtin_popcount(i))]+1;
    f(i, 0, n) b += (s[i] == '1');
    int inc = b+1, dec = b-1;
    if(b == 0)
    {
    	f(i, 0, n) cout<<"1\n";
    	return;
    }
    if(b == 1)
    {
    	f(i, 0, n)
    	{
    		if(s[i] == '1') cout<<"0\n";
    		else
    		{
    			if(i == n-1) cout<<"2\n";
    			else if(s[n-1] == '1') cout<<"2\n";
    			else cout<<"1\n";
    		}
    	}
    	return;
    }
    f(i, 0, n)
    {
    	modinc += (s[i]-'0')*powM(2, n-1-i, inc);
    	modinc %= inc;
    }
    f(i, 0, n)
    {
    	moddec += (s[i]-'0')*powM(2, n-1-i, dec);
    	moddec %= dec;
    }
    f(i, 0, n)
    {
    	if(s[i] == '1') cout<<cnt[((moddec - powM(2, n-1-i, dec))%dec + dec)%dec]+1<<endl;
    	else cout<<cnt[((modinc + powM(2, n-1-i, inc))%inc + inc)%inc]+1<<endl;
    }
}

int32_t main()
{
    IOS
    int t = 1;
    // cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5308
from sys import stdin, stdout

input = lambda: stdin.readline()
write = stdout.write

def main():
    X1, Y1, X2, Y2 = map(int, input().split())

    l1 = abs(max(X1, X2) - min(X1, X2))
    l2 = abs(max(Y1, Y2) - min(Y1, Y2))
    if X1 <= X2 and Y1 <= Y2:
        x3 = X2 - l2
        y3 = Y2 + l1
        x4 = x3 - l1
        y4 = y3 - l2
    elif X1 > X2 and Y1 < Y2:
        x3 = X2 - l2
        y3 = Y2 - l1
        x4 = x3 + l1
        y4 = y3 - l2
    elif X1 >= X2 and Y1 >= Y2:
        x3 = X2 + l2
        y3 = Y2 - l1
        x4 = x3 + l1
        y4 = y3 + l2
    elif X1 < X2 and Y1 > Y2:
        x3 = X2 + l1
        y3 = Y2 + l2
        x4 = x3 - l2
        y4 = y3 + l1
    print(x3, y3, x4, y4)

main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[10];
    cin>>s;
    if((strcmp(s,"Sunny"))==0)
       cout<<"Cloudy"<<endl;
    else if((strcmp(s,"Cloudy"))==0)
        cout<<"Rainy"<<endl;
    else
        cout<<"Sunny"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int n, m;
    cin >> n >> m;
    int d[n][n] = {};
    int a[m], b[m], c[m];
    int q = 1001*m;
    for(int i = 0;i <n;i++){
        for(int j = 0;j <n;j++){
            if(i!=j)d[i][j]= q;
        }
    }
    for(int i = 0;i<m;i++){
        cin >>a[i] >>b[i] >>c[i];
        d[a[i]-1][b[i]-1]=c[i];
        d[b[i]-1][a[i]-1]=c[i];
    }
    for(int i =0;i<n;i++){
        for(int j =0;j<n;j++){
            for(int k =0;k<n;k++){
                d[j][k] = min(d[j][k],d[j][i]+d[i][k]);
            }
        }
    }
    int t =0;
    for(int i =0;i<m;i++){
        if(d[a[i]-1][b[i]-1]<c[i])t++;
    }
    cout << t ;
return 0;
}

Measured memory_bytes: 384
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
	}

	sort.Ints(a)
	const mod = 1000000007
	ans := 1
	if n%2 == 0 {
		cnt := 1
		for i := 0; i < n; i += 2 {
			if !(a[i] == cnt && a[i+1] == cnt) {
				fmt.Println(0)
				return
			}

			cnt += 2
			ans *= 2
			ans %= mod
		}
	} else {
		if a[0] != 0 {
			fmt.Println(0)
			return
		}

		cnt := 2
		for i := 1; i < n; i += 2 {
			if !(a[i] == cnt && a[i+1] == cnt) {
				fmt.Println(0)
				return
			}

			cnt += 2
			ans *= 2
			ans %= mod
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 2048
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

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

  string line;
  while(getline(cin,line)){
	if(line == ".") break;
	int p1 = 0, p2 = 0, i;

	bool ans = true;
	stack<int> st;
	for(i=0;i<SZ(line);++i){
	  switch(line[i]){
	  case '(':
		st.push(0); break;
	  case '[':
		st.push(1); break;
	  case ')':
		if(st.empty())
		  ans = false;		
		else{
		  if(st.top() != 0)
			ans = false;			
		  st.pop();
		}
		break;
	  case ']':
		if(st.empty())
		  ans = false;		
		else{
		  if(st.top() != 1)
			ans = false;			
		  st.pop();
		}
		break;
	  }
	}
	ans = ans && st.empty();
	cout << (ans? "yes": "no") << endl;
  }

  return 0;
}

Measured memory_bytes: 1180
#define _CRT_SECURE_NO_WARINGS
#include<iostream>
#include<iomanip>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<fstream>
#include<map>
#include<unordered_map>
using namespace std;
typedef int me;
typedef long long ll;
typedef unsigned long long ull;
#define andrew  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl '\n'
#define sz(v)(int)(v.size())
#define all(v) v.begin(),v.end()
#define PI 3.1415926535
#define sin(i) (long double)sin(i*PI/180.0);
#define OO 1e18;
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ull lcm(ll x, ll y) { return x / gcd(x, y) * y; }
void the_end() {
#ifndef ONLINE_JUDGE;
    system("pause");
#endif
}
int dy8[] = { 0,0,1,-1,1,-1,-1,1 };
int dx8[] = { 1,-1,0,0,1,-1,1,-1 };
int id8[] = { 0, 1,2,3,4, 5,6, 7 };
// you can be specialist 
// soon will be (Cyain)
ll n, m;
vector<pair<ll,ll>>v;
ll mm[101][100001];
ll solve(int i,ll w)
{
    if (i == n)
        return 0;
    if (mm[i][w] != 0)
        return mm[i][w];
    mm[i][w] = solve(i + 1, w);
    if (w - v[i].first >= 0) {
        mm[i][w] = max(mm[i][w], solve(i + 1, w - v[i].first) + v[i].second);
    }
    return mm[i][w];
}
int main()
{
    andrew;
    cin >> n >> m;
    v.resize(n);
    for (int i = 0; i < n; i++)cin >> v[i].first >> v[i].second;
    cout << solve(0, m) << endl;
    the_end();
}

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

int main(int argc, char const *argv[])
{
	int n; cin >> n;
	vector<vector<int>> cnt(10, vector<int>(10, 0)); {
		for (int i = 1; i <= n; i++) {
			string s = to_string(i);
			cnt[s[0] - '0'][s[s.size() - 1] - '0']++;
		}
	}

	ll ans = 0;
	for (int i = 1; i <= 9; ++i) {
		for (int j = 1; j <= 9; ++j) {
			ans += (ll)cnt[i][j] * cnt[j][i];
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
input = sys.stdin.readline
N,M= map(int,input().split())
H = [0] + list(map(int,input().split()))
g = defaultdict(list)

for i in range(M):
    A,B = map(int,input().split())
    g[A].append(B)
    g[B].append(A)

ans = 0
for i in range(1,N+1):
    if len(g[i]) == 0:
        ans += 1
    elif H[i] > max([H[j] for j in g[i]]):
        ans += 1
print(ans)





Measured memory_bytes: 99164
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;


public class Main {
	private	static	BufferedReader	br = null;
	private	static	RecordCmp		rc = null;

	static {
		br = new BufferedReader(new InputStreamReader(System.in));
		rc = new RecordCmp();
	}
 
    /**
     * @param args
     */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Record[]	rec  = null;
		Record[][]	recs = null;

		while ((rec = parseRecord()) != null) {
			recs = new Record[4][];
			recs[0] = rec;
			recs[1] = parseRecord();
			recs[2] = parseRecord();
			recs[3] = new Record[6];

			for (int i = 0; i < 6; i++) {
				recs[3][i] = recs[i/2][2+i%2];
			}
			Arrays.sort(recs[3], rc);

			for (int i = 0; i < 8; i++) {
				System.out.println(recs[i/2][i%2].n+" "+recs[i/2][i%2].t);
			}
		}
	}
 
	private static Record[] parseRecord() {
		Record[]	rec = null;

		for (int i = 0; i < 8; i++) {
			String	str = parseStdin();
			if (str == null) break;
			if (rec == null) rec = new Record[8];
			rec[i] = new Record(str.split(" "));
			if (i == 7) Arrays.sort(rec, rc);
		}
		return rec;
	}
 
	private static String parseStdin() {
        String  stdin = null;
        
        try {
        	String  tmp = br.readLine();
        	if (tmp != null) {
            	if (!tmp.isEmpty()) stdin = tmp;
        	}
        }
        catch (IOException e) {}
 
        return stdin;
	}
}

class Record {
	public	int		n;
	public	double	t;

	public Record(String[] param) {
		n = Integer.parseInt(param[0]);
		t = Double.parseDouble(param[1]);
	}
}

class RecordCmp implements Comparator<Record> {
   public int compare(Record rc1, Record rc2) {
       return (rc1.t < rc2.t) ? -1 : (rc1.t > rc2.t) ? 1 : 0;
   }
}

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

typedef long long LL;
typedef pair<LL, LL> II;

LL sum(LL l, LL r) {
    return (r - l + 1) * (r + l) / 2;
}

int main() {
    LL n, x, d;
    cin >> n >> x >> d;

    if (d == 0) {
        set<LL> s;
        for (int a = 0; a <= n; ++a) {
            s.insert(a * x - (n - a) * x);
        }
        cout << s.size() << endl;
        return 0;
    }

    if (d < 0) {
        d = -d;
        x = x - d * (n - 1);
    }

    map<int, vector<II>> f;
    for (int a = 0; a <= n; ++a) {
        LL l = sum(0, a - 1);
        LL r = sum(n - a, n - 1);
        l -= n * (n - 1);
        r -= n * (n - 1);
        LL t = x * (2 * a - n);
        LL z = t % (2 * d);
        if (z < 0) {
            z += 2 * d;
        }
        f[z].push_back(II(t + l * 2 * d, t + r * 2 * d));
    }

    LL ans = 0;
    for (auto it = f.begin(); it != f.end(); ++it) {
        vector<II> a = it->second;
        sort(a.begin(), a.end());
        for (int i = 0; i < (int)a.size(); ++i) {
            int j = i;
            LL p = a[i].second;
            while (j + 1 < (int)a.size() && a[j + 1].first <= p) {
                j += 1;
                p = max(p, a[j].second);
            }
            ans += (p - a[i].first) / (2 * d) + 1;
            i = j;
        }
    }

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


Measured memory_bytes: 22144
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll>
#define P pair<ll,ll> 
#define rep(i,n) for(ll (i)=0; (i)<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  lvector v(3,0);
  vector<lvector> c(3,v);
  rep(i,3)rep(j,3) cin>>c[i][j];
  const vector<lvector> C(c);
  ll mn=1e9+7;rep(i,3) mn=min(mn,C[i][0]);
  bool isok=false;
  rep(i,mn+1) {
    vector<lvector> C_(C);
    rep(j,3) C_[j][0]-=i;
    rep(j,2) C_[0][j+1]-=C_[0][0];
    rep(j,2) C_[1][j+1]-=C_[1][0];
    rep(j,2) C_[2][j+1]-=C_[2][0];
    if(  C_[0][1]==C_[1][1]&&C_[1][1]==C_[2][1]
       &&C_[0][2]==C_[1][2]&&C_[1][2]==C_[2][2]
       &&C_[0][1]>=0&&C_[0][2]>=0) {
         isok=true;break;
       }
  }
  if(isok) puts("Yes");else puts("No");
  return 0;
}

Measured memory_bytes: 256