akhauriyash/Code-Regression huggingface dataset:
#include<iostream>

int main(){
  int num[101]={};
  int number,max;

  while(std::cin >> number){
    ++num[number];
  }
  max = 0;
  for(int i=1;i<101;i++){
    if(num[i]>max){
      max = num[i];
    }
  }
  for(int i=1;i<101;i++){
    if(num[i]==max){
      std::cout << i << std::endl;
    }
  }
}

Measured memory_bytes: 3012
#include<bits/stdc++.h>
using namespace std;
  
int main() {
	long long pw[11]; pw[0] = 1;
	for (int i = 1; i <= 10; ++i) pw[i] = 1ll * pw[i - 1] * 10;
	int num = 0;
	for (int i = 1 ; i <= 10; ++i)   {
		cout << "? " << pw[i] << "\n";
		cout.flush();
		char c; cin >> c;
		if(c == 'N') {
			num = i;
			break;
		}
	}
	
	if(num == 0) {
		for(int i = 1; i <= 10; ++i) {
			cout << "? " << pw[i] - 1 << "\n";
			cout.flush();
			char c; cin >> c;
			if(c == 'Y') {
				cout << "! " << pw[i - 1] << "\n";
				cout.flush(); exit(0);
			}
		}
	}
	
	long long l = pw[num - 1], r = pw[num] - 1;
	while(l < r)   {
		long long mid = (l + r) >> 1;
		cout << "? " << mid * 10 << "\n";
		cout.flush();
		char c; cin >> c;
		if(c == 'Y') r = mid;
		else l = mid + 1;
	}
	cout << "! " << l << "\n";
	cout.flush();
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
using namespace std;
int n;
int main()
{
	cin>>n;
	int ans=0,q;
	for(int i=1;i<=n;i++)
	{
		cin>>q;
		while(q%2==0)
		{
			q/=2;
			ans++;
		}
	}
	cout<<ans;
	return 0;
}

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

#define INF (INT_MAX/2-1)
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

int main(){
  string s;
  int x,y;
  cin>>s>>x>>y;
  vector<int>m;
  int n=0;
  for(int i=0;i<s.size();i++){
    if(s[i]=='T')m.push_back(n),n=0;
    else{
      n++;
      if(i==s.size()-1)m.push_back(n);
    }
  }
  vector<int>mx,my;
  int f=m[0];
  for(int i=1;i<m.size();i++){
    if(i%2)my.push_back(m[i]);
    else mx.push_back(m[i]);
  }
  x-=f;
  sort(rrng(mx));
  sort(rrng(my));

  for(auto it:mx){
    x=abs(abs(x)-it);
  }
  for(auto it:my){
    y=abs(abs(y)-it);
  }
  if(x!=0||y!=0)cout<<"No"<<endl;
  else cout<<"Yes"<<endl;
  return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr long long int infll = 1001001001001001LL;
constexpr int INF = 1000000007;
constexpr int inf = 1000000007;
const int mod = 1000000007;

template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}

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

ll lcm(ll a, ll b)
{
    return a / gcd(a, b) * b;
}

inline double nCr(const int n, int r)
{
    if (n == 0)
    {
        return 0;
    }
    if (r == 0)
    {
        return 1;
    }
    if (r == 1)
    {
        return n;
    }
    if (n == r)
    {
        return 1;
    }

    if (r > n / 2)
    {
        r = n / 2;
    }

    double result = 1;
    for (double i = 1; i <= r; i++)
    {
        result *= (n - i + 1) / i;
    }

    return (result);
}

template <typename T>
T seinomi(T a)
{
    if (a > 0)
    {
        return a;
    }
    else
    {
        return 0;
    }
}

template <typename T>
map<T, T> soinsuubunkai(T n) //連想配列[素因数f.first][個数f.second]
{
    map<T, T> ret;
    for (T i = 2; i * i <= n; i++)
    {
        while (n % i == 0)
        {
            ret[i]++;
            n /= i;
        }
    }
    if (n != 1)
        ret[n] = 1;
    return ret;
}

template <typename T>
T ketasuu(T num)
{
    return std::to_string(num).length();
}

int kaizyou(int k)
{
    int sum = 1;
    for (int i = 1; i <= k; ++i)
    {
        sum *= i;
    }
    return sum;
}

template <class ForwardIt, class T>
void iota(ForwardIt first, ForwardIt last, T value)
{
    while (first != last)
    {
        *first++ = value;
        ++value;
    }
}

//nの階乗を計算
int factorial(int n)
{
    int answer = 1;
    while (n > 1)
    {
        answer *= n;
        n--;
    }
    return answer;
}
int comb(int n, int r)
{
    return factorial(n) / (factorial(r) * factorial(n - r));
}

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0)
    {
        if (n & 1)
            res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


template <typename T>
T amarinasi(T a,T b){
    if(a%b==0)
{
    return a/b;
}
else if(a%b>0)
{
    return a/b+1;
}
else
{
    return a/b-1;
}
}

//小数点以下10桁テンプレート（main関数内の最初に貼付け）
//std::cout << std::fixed << std::setprecision(10);

//----------------------------------------------------------------

int main(){
ll d,n;
cin>>d>>n;
ll cnt=0;
for(ll i=pow(100,d);i<=10000000;i+=pow(100,d)){
    if(i%(ll)pow(100,d+1)!=0){
        cnt++;
    }
    if(cnt==n){
        cout<<i<<endl;
        break;
    }
}
}












Measured memory_bytes: 256
from sys import stdin

# read input
n,m = [int(x) for x in stdin.readline().strip().split()]
sc_dict = {}

# create dict
for _ in range(m):
  s, c = [int(x) for x in stdin.readline().strip().split()]
  if s in sc_dict.keys(): sc_dict[s].append(c)
  else: sc_dict[s] = [c]
    
# get min
min_val = list(str(10**(n-1))) if n > 1 else ['0']
for k, v in sc_dict.items():
  if len(v) != 1 and len(set(v)) > 1:
    print('-1')
    exit()
  min_val[k-1] = str(v[0])
  
min_val = ''.join(min_val)
if len(min_val) > 1 and int(min_val) == 0:
  print('-1')
else:
  print(''.join(min_val))

Measured memory_bytes: 9228
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
from collections import Counter
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product

def resolve():
    N=int(input())
    S=[''.join(sorted(input())) for i in range(N)]
    C=Counter(S)
    print(sum(i*(i-1)//2 for i in C.values()))






resolve()

Measured memory_bytes: 68440
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define int long long int
#define pb push_back
#define fi first
#define se second
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define all(x) x.begin(), x.end()
#define IO ios :: sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define pii pair<int,int>
const int mod = 1e9 + 7;
const int mod1 = 998244353;
typedef long double f80;
#ifndef LOCAL
#define endl '\n'
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rand(int l, int r){
    uniform_int_distribution<int> uid(l, r);
    return uid(rng);
}
const int N = 1e5 + 5;
int a[N];
void solve(){
    int n;
    cin >> n;
    int ans = 1;
    fr(i, 1, n) cin >> a[i];
    sort(a + 1, a + n + 1);
    fr(i, 1, n){
        int g = __gcd(a[i], i - 1);
        ans = (ans * g) % mod1;
    }
    cout << ans << endl;
}
signed main()
{
    IO;
    #ifdef LOCAL
        freopen("inp.txt", "r", stdin);
        // freopen("out.txt", "w", stdout);
    #endif
    clock_t clk = clock();
    int t = 1;
    // cin >> t;
    fr(i, 1, t){
        solve();
    }
    cerr << endl << setprecision(10) << fixed << (double)(clock() - clk) / CLOCKS_PER_SEC;
    return 0;
};

Measured memory_bytes: 1024
//master
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextDouble();
        p(Math.PI*n*2);
    }
    public static <T> void p(T message) {
        System.out.println(message);
    }

    public static <T> void pe(T message) {
        System.err.println(message);
    }

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


Measured memory_bytes: 37388
M=Math
while 0<n=gets.to_i
z=(1..n).map{gets.split.map &:to_i}
gets.to_i.times{x,y,t,u=gets.split.map &:to_i
puts z.any?{|p,q,r|w=M.hypot(c=p-t,d=q-u)>r
r<M.hypot(a=p-x,b=q-y)?!w||((e=t-x)*b-(f=u-y)*a).abs<=r*M.hypot(x-t,y-u)&&(e*a+f*b)*(e*c+f*d)<0:w
}?:Safe:"Danger"}end

Measured memory_bytes: 6148
package main

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

var (
	N, x, y, z int
	dp         [301][301][301]float64
)

func readVariables() {
	N = nextInt()
	for i := 0; i < N; i++ {
		a := nextInt()
		switch a {
		case 1:
			x++
		case 2:
			y++
		case 3:
			z++
		}
	}
}

func solve(x, y, z int) float64 {
	if x == 0 && y == 0 && z == 0 {
		return 0
	}
	if dp[x][y][z] > 0 {
		return dp[x][y][z]
	}
	result := 0.0
	S := x + y + z
	if x > 0 {
		result += solve(x-1, y, z) * float64(x) / float64(S)
	}
	if y > 0 {
		result += solve(x+1, y-1, z) * float64(y) / float64(S)
	}
	if z > 0 {
		result += solve(x, y+1, z-1) * float64(z) / float64(S)
	}
	result += float64(N) / float64(S)
	dp[x][y][z] = result
	return result
}

func main() {
	readVariables()
	fmt.Println(solve(x, y, z))
}

/* 以下、テンプレート*/

var scanner *bufio.Scanner

func init() {
	Max := 1001001
	scanner = bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 0, Max), Max)
	scanner.Split(bufio.ScanWords)
}

//nextInt converts next token from stdin and returns integer value.
//nextInt panics when conversion into an integer fails.
func nextInt() int {
	if !scanner.Scan() {
		panic("No more token.")
	}
	num, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic("nextInt(): cannot convert to int: " + scanner.Text())
	}
	return num
}

func nextStr() string {
	if !scanner.Scan() {
		panic("No more token.")
	}
	return scanner.Text()
}

// MinInt は、2つの整数を受け取り、最小値を返します。
func MinInt(x, y int) int {
	if x < y {
		return x
	} else {
		return y
	}
}

//MaxInt は、2つの整数を受け取り、最大値を返します。
func MaxInt(x, y int) int {
	if x < y {
		return y
	} else {
		return x
	}
}

//AbsInt は、整数の絶対値を返します。
func AbsInt(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

//ModPow は整数の累乗関数で、剰余もサポートします。
//base^exponentの値をmoduleで割った余りを返します。
//moduloが1以下の場合には、剰余演算をしません。
//baseが負の値である場合には、返す値が負になることがあります。
func ModPow(base, exponent, modulo int) (result int) {
	result = 1
	for exponent > 0 {
		if exponent%2 == 1 {
			result *= base
			if modulo > 1 {
				result %= modulo
			}
		}
		base *= base
		if modulo > 1 {
			base %= modulo
		}
		exponent /= 2
	}
	return
}

//Gcd は、引数の整数全ての最大公約数を返します。
func Gcd(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = gcd(result, vals[i])
	}
	return
}

func gcd(x, y int) int {
	x, y = AbsInt(x), AbsInt(y)
	for y > 0 {
		x, y = y, x%y
	}
	return x
}

//Lcm は、与えられた整数の最小公倍数を返します。
func Lcm(vals ...int) (result int) {
	if len(vals) == 0 {
		return
	}
	result = vals[0]
	for i := 1; i < len(vals); i++ {
		result = lcm(result, vals[i])
	}
	return
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}


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

int g(int x){
  int z=0;
  while(x>0){
    z+=x%10;
    x/=10;
  }
  return z;
}
      
  
int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int ans=0;
  for(int i=1;i<=N;i++){
    if(g(i)>=A&&g(i)<=B){
      ans+=i;
    }
  }
  cout << ans << endl;
}

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

#define __STDC_FORMAT_MACROS
#define p64 PRId64

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define ALL(f, x, ...)                                                         \
    ([&] (decltype ((x)) ALL) {                                                \
        return (f) (begin (ALL), end (ALL), ##__VA_ARGS__);                    \
    }) (x)

using namespace std;
using ll = int64_t;

int main() {
    int H, N;
    cin >> H >> N;
    int A, accum;
    accum = 0;
    REP (i, N) {
        cin >> A;
        accum += A;
    }
    cout << (1 < (double)H / accum ? "No" : "Yes") << endl;
    return 0;
}


Measured memory_bytes: 256
use std::io::Read;

const MOD: u64 = 1000001137;
const RAD: u64 = 29;

fn mod_pow(r: u64, mut n: u64) -> u64 {
    let mut t = 1;
    let mut s = r;
    while n > 0 {
        if n & 1 == 1 {
            t = t * s % MOD;
        }
        s = s * s % MOD;
        n >>= 1;
    }
    t
}

fn can(a: &Vec<u64>, len: usize) -> bool {
    let n = a.len() - 1;
    if len * 2 > n {
        return false;
    }
    let f = mod_pow(RAD, len as u64);
    let mut set = std::collections::HashSet::new();
    for i in len..(n + 1 - len) {
        let v = (a[i - len] + MOD * MOD - f * a[i]) % MOD;
        set.insert(v);
        let v = (a[i] + MOD * MOD - f * a[i + len]) % MOD;
        if set.contains(&v) {
            return true;
        }
    }
    false
}

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let s: Vec<char> = it.next().unwrap().trim().chars().collect();
    let mut a = vec![0; n + 1];
    for i in (0..n).rev() {
        a[i] = (a[i + 1] * RAD + s[i].to_digit(36).unwrap() as u64 - 10) % MOD;
    }
    let mut l = 0;
    let mut r = n / 2 + 1;
    while r - l > 1 {
        let m = (l + r) / 2;
        if can(&a, m) {
            l = m;
        } else {
            r = m;
        }
    }
    println!("{}", l);
}

fn main() {
    run();
}


Measured memory_bytes: 4352
//Bokann ga bokka--nn!!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<P,int> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
int val[105][105]={};
bool vis[105][105]={};
int main(){
	int w,h;
	cin >> w >> h;
	for(int i=1;i<=h;i++)
	{
		for(int j=1;j<=w;j++)
		{
			cin >> val[j][i];
		}
	}
	queue<P>que;
	que.push(mp(0,0));
	int ret=0;
	while(!que.empty())
	{
		 P p=que.front(); que.pop();
		 int x=p.first;
		 int y=p.second;
		 if(vis[x][y]) continue;
		 vis[x][y]=true;

		 if(y%2==0)
		 {
		 	int dx[6]={-1,0,1,0,-1,-1};
		 	int dy[6]={-1,-1,0,1,1,0};
			 for(int i=0;i<6;i++)
			 {
		 		int xx=x+dx[i];
		 		int yy=y+dy[i];
		 		if(0<=xx && xx<=w+1 && 0<=yy && yy<=h+1)
		 		{
		 			if(!val[xx][yy])
		 			{
		 				que.push(mp(xx,yy));
		 			}
		 			else
		 			{
		 				ret++;
		 			}
		 		}
			 }
		 }
		 else
		 {
		 	int dx[6]={0,1,1,1,0,-1};
		 	int dy[6]={-1,-1,0,1,1,0};
			 for(int i=0;i<6;i++)
			 {
		 		int xx=x+dx[i];
		 		int yy=y+dy[i];
		 		if(0<=xx && xx<=w+1 && 0<=yy && yy<=h+1)
		 		{
		 			if(!val[xx][yy])
		 			{
		 				que.push(mp(xx,yy));
		 			}
		 			else
		 			{
		 				ret++;
		 			}
		 		}
			 }
		 }

	}
	cout << ret << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#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 mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    int nx=0,ny=0,now=0;
    rep(i,n){
        int t,x,y; cin>>t>>x>>y;
        int d = abs(x-nx)+abs(y-ny);
        if (!(d<=t-now && d%2==(t-now)%2)){
            cout<<"No\n";
            return 0;
        }
        nx=x, ny=y;
        now = t;
    }
    cout<<"Yes\n";
    return 0;
}


Measured memory_bytes: 256
/*
    NEVER GIVE UP!
    THE EXPERT IN ANYTHING WAS ONCE A BEGINNER
*/
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define f(i,a,b) for(ll i=a; i<=b; i++)
#define fi(i,a,b) for(ll i=a; i>=b; i--)
#define fa(x,b) for(auto x:b)
#define TC ll test_case; cin>>test_case; for(ll number=1 ; number <= test_case ; number ++ )
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp make_pair
#define ff first
#define ss second
#define sz(a) (ll)(a).size()
#define sp(x) cout << fixed << setprecision(x);
#define ReadFile freopen("input.txt","r",stdin)
#define WriteFile freopen("output.txt","w",stdout)
#define endl "\n"

const ld pi = acos(-1);
const ll M=1e9+7,N=1e7+5,INF=1e18;

void solve()
{
    string s;
    cin >> s;
    
    if(s=="MON")
        cout << 6;
    else if(s=="TUE")
        cout << 5;
    else if(s=="WED")
        cout << 4;
    else if(s=="THU")
        cout << 3;
    else if(s=="FRI")
        cout << 2;
    else if(s=="SAT")
        cout << 1;
    else if(s=="SUN")
        cout << 7;
}

int32_t main()
{
    FIO
    solve();
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k,a=1;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		if(a<k)
		{
			a=a*2;
		}
		else
		{
			a=a+k;
		}
	}
	cout<<a;
	return 0;
}

Measured memory_bytes: 3532
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> ipair;
typedef tuple<int, int, int> ituple;

// const int INF = INT_MAX;
// const ll INF = LLONG_MAX;
const int MOD = ((int)1e9 + 7);
// const ld EPS = (1e-10);
#define PI acosl(-1)
#define MAX_N (100000 + 2)

int n;
VI edges[MAX_N];
ll dp[MAX_N][2];

const int WHITE = 0;
const int BLACK = 1;

ll rec(int to, int from, int color){
  if (dp[to][color] != -1){
    return dp[to][color];
  }

  ll result = 1;

  // printf("to = %d, from = %d, color = %d start.\n", to, from, color);
  for (int i = 0; i < edges[to].size(); i++){
    if (edges[to][i] == from){
      continue;
    }

    if (color == WHITE){
      ll tmp = (rec(edges[to][i], to, WHITE) + rec(edges[to][i], to, BLACK)) % MOD;
      result = (result * tmp) % MOD;
    }
    else{
      result = (result * rec(edges[to][i], to, WHITE)) % MOD;
    }
  }

  dp[to][color] = result;
  // printf("to = %d, from = %d, color = %d = %lld end.\n", to, from, color, dp[to][color]);
  return dp[to][color];
}

void exec(){
  cin >> n;

  for (int i = 0; i < MAX_N; i++){
    for (int j = 0; j < 2; j++){
      dp[i][j] = -1;
    }
  }
  for (int i = 0; i < n-1; i++){
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    edges[x].push_back(y);
    edges[y].push_back(x);
  }

  cout << (rec(0, -1, WHITE) + rec(0, -1, BLACK)) % MOD << endl;

}

void solve(){
  int t = 1;
  // scanf("%d", &t);
  for (int i = 0; i < t; i++){
    exec();
  }
}

int main(){
  solve();
  return 0;
}


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

bool prime[10001];

void init_prime() {
    fill(prime, prime+10001, true);
    prime[0] = prime[1] = false;
    for (int i = 3; i <= 100; i += 2) {
        if (prime[i]) {
            for (int d = i + i, j = i + d; j <= 10000; j += d) {
                prime[j] = false;
            }
        }
    }
}

int main() {
    int N, c[] = {0, 0, 0, 1, 2};

    init_prime();

    while (cin >> N) {
        int count = 0;
        if (N < 5) {
            count = c[N];
        }
        else if ((N & 1) == 0) {
            if (prime[N-1]) count = 2;
        }
        else {
            for (int i = 3, j = N - 2; i <= N - 2; i += 2, j -= 2) {
                if (prime[i] && prime[j]) count++;
            }
        }
        cout << count << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
N = int(input())
a = map(int, input().split())

color_set = set()
original_cnt = 0
red_flag = False
for val in a:
    if val >= 3200:
        original_cnt += 1
    else:
        if val >= 2800:
            red_flag = True
        color_set.add(int(val / 400))
if red_flag is True:
    print('{} {}'.format(len(color_set), len(color_set) + original_cnt))
else:
    if original_cnt > 0:
        print('{} {}'.format(len(color_set) + 1, len(color_set) + original_cnt))
    else:
        print('{} {}'.format(len(color_set), len(color_set)))


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d %d",&a,&b);
	double c;
	int d;
	c=(a+b)/2.0;
	d=(int)c;
	if(c-d<0.5)
	printf("%d\n",d);
	else
	printf("%d\n",d+1);
}

Measured memory_bytes: 128
{-# LANGUAGE MultiWayIf #-}

import Data.List (minimumBy)

showIs is it = show is++" "++show it

solveSimple [] _ = []
solveSimple ((a,i):as) (maxA,maxI) = showIs maxI i:solveSimple as (a+maxA,i)

solveRev [] _ = []
solveRev ((a,i):rs) (minA,minI) = showIs minI i:solveRev rs (a+minA,i)


main :: IO ()
main = do
  n <- read <$> getLine :: IO Int
  as <- map read.words <$> getLine :: IO [Integer]
  let ais = zip as [1..] :: [(Integer,Integer)]
      (maxA,maxI) = maximum ais
      (minA,minI) = minimum ais
      ans = if | minA >= 0 -> solveSimple ais (maxA, maxI)
               | maxA < 0 -> solveRev (reverse ais) (minA, minI)
               | abs maxA >= abs minA ->
                  [showIs maxI i|(a,i)<-ais, a<0] ++
                  solveSimple (map (\(a,i)->if a < 0 then (a+maxA,i) else (a,i)) ais) (maxA, maxI)
               | otherwise ->
                  [showIs minI i|(a,i)<-ais, a>=0] ++
                  solveRev (map (\(a,i)->if a >= 0 then (a+minA,i) else (a,i)) (reverse ais)) (minA, minI)
  print $ length ans
  putStr $ unlines ans


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

int main(){
    int n, m, k;
    cin >> n >> m >> k;
    bool flag = false;
    if(k % n == 0)flag = true;
    else if(k % m == 0)flag = true;
    else{
        for(int i=1;i<=m;++i){
            for(int j=1;j<=n;++j){
                if((i*n + j*m - (2*i*j)) == k)flag = true;
            }
        }
    }
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long M=1e9+7;
int main(){
	int h,w;
	cin>>h>>w;
	vector<vector<char>> grid(h+1,vector<char>(w+1,'.'));
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>grid[i][j];
	vector<vector<long long>> dp(h+1,vector<long long>(w+1,0)); 
	// dp[i][j] will store number of ways to come to i-th row and j-th column 
	for(int row=1;row<=h;row++){
		for(int column=1;column<=w;column++){
			if(row==1 and column==1)
				dp[row][column]=1;
			else if(grid[row][column]=='#')
				dp[row][column]=0;
			else
				dp[row][column]=((row-1<1 ? 0 : dp[row-1][column])
								+(column-1<1 ? 0 : dp[row][column-1]))%M;
		}
	}
	cout<<dp[h][w]<<endl;
	return 0;
}

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

int dp[100001];

int solve(int* arr, int i, int n, int k) {
	if(i==n) return 0;
  
    if(dp[i] != -1) return dp[i];

  	int op1 =10e8;
  	//int op2 =10e8;
  
  	for(int j=1; j<=k; j++) {
          if(i+j<=n) {
              int val = abs(arr[i+j] - arr[i]) + solve(arr, i+j, n, k);
              op1 = min(op1, val);
          }
      }
  
  	return dp[i] = op1;

}
 
int main() {
  	int n;
  	cin>>n;
  	
    int k;
    cin>>k;

  	int* arr = new int[n];
  	for(int i=0; i<n; i++) cin>>arr[i];
    memset(dp, -1, sizeof(dp));
  	cout<<solve(arr, 0, n-1, k);
  	
	return 0;
}

Measured memory_bytes: 13780
package main

import (
	"bufio"
	"fmt"
	"os"
)

var r = bufio.NewReader(os.Stdin)
var w = bufio.NewWriter(os.Stdout)

func main() {
	defer w.Flush()

	var b string
	fmt.Fscanf(r, "%s\n", &b)

	switch b {
	case "A":
		fmt.Fprintf(w, "%s\n", "T")
	case "T":
		fmt.Fprintf(w, "%s\n", "A")
	case "G":
		fmt.Fprintf(w, "%s\n", "C")
	case "C":
		fmt.Fprintf(w, "%s\n", "G")
	}
}

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

int main(){
	int n;
  	cin >> n;
  vector<int> nums(n);
  for(int i = 0; i < n; i++) cin >> nums[i];
  
  int res = 0;
  
  for(int i = 1; i < n - 1; i++){
    if(nums[i - 1] > nums[i] && nums[i] > nums[i + 1]) res++;
    else if(nums[i - 1] < nums[i] && nums[i] < nums[i + 1]) res++;
  }
  
  cout << res;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define pb push_back
#define f first
#define s second
using namespace std;


ll gcd(ll a, ll b)   //Function to find gcd of two numbers
{
    if (a == 0)
    return b;
    return gcd(b % a, a);
}

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

    int x;
    cin>>x;

    if(x==0)
    cout<<1<<endl;
    else if(x==1)
    cout<<0<<endl;

    return 0;
}

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

using namespace std;

int main () {
  long long a,b,k;
  cin >>a>>b>>k;
 
  if(k<=a){
    cout <<a-k<<" "<<b<<endl;
  } else if(k<a+b){
    cout <<0<<" "<<b-(k-a)<<endl;
  } else{
    cout <<0<<" "<<0<<endl;
  }
}

Measured memory_bytes: 256
h,w,a,b=map(int,input().split())
n=h+w
MOD = 10**9+7

def inv_mod(a, p=MOD):
    def inv_mod_sub(a, p):
        if a == 1:
            return 1, 0
        else:
            d, r = p//a, p%a
            x, y = inv_mod_sub(r, a)
            return y-d*x, x
    if p < 0: p = -p
    a %= p
    return inv_mod_sub(a,p)[0] % p

def comb_mod(n, k):
    if k < 0 or k > n:
        return 0
    else:
        return f_mod[n]*f_mod_inverse[k]*f_mod_inverse[n-k] % MOD
f_mod=[1]*(n+1)
f_mod_inverse=[1]*(n+1)
for i in range(1,n+1):
  f_mod[i]=f_mod[i-1]*i%MOD
  f_mod_inverse[i]=f_mod_inverse[i-1]*inv_mod(i)%MOD

ans=0
for i in range(h-a):
    ans+=(comb_mod(i+b-1,i)*comb_mod(w-b-1+h-i-1,h-i-1))%MOD
print(ans%MOD)


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

int main() {
  int n;
  cin >> n;
  if(n/100==7)cout<<"Yes"<<endl;
  else {
    n%=100;
    if(n/10==7)cout<<"Yes"<<endl;
    else {
      n%=10;
      if(n==7)cout<<"Yes"<<endl;
      else cout<<"No"<<endl;
    }
  }
}

Measured memory_bytes: 3540
from collections import deque


def main():
    N, M = map(int, input().split())
    adj = [set() for _ in range(N)]
    for _ in range(M):
        A, B = map(int, input().split())
        adj[A-1].add(B-1)
        adj[B-1].add(A-1)
    ans = [-1] * N
    q = deque([(0, 0)])
    while len(q):
        cur, prev = q.popleft()
        if ans[cur] != -1:
            continue
        ans[cur] = prev
        for nxt in adj[cur]:
            if ans[nxt] == -1:
                q.append((nxt, cur))
    print("Yes")
    for i in range(1, N):
        print(ans[i]+1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 121380
#include <iostream>
#include <deque>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;
using ll = long long;
using ull = unsigned long long;

namespace std {
	template<typename Iterator>
	Iterator begin(pair<Iterator, Iterator> p) {
		return p.first;
	}
	template<typename Iterator>
	Iterator end(pair<Iterator, Iterator> p) {
		return p.second;
	}
}

bool search(
	deque<ll>& q,
	vector<ll>& v,
	unordered_map<ll, unordered_set<ll>>& e
) {
	while(!q.empty()){
		auto const current = q.front();
		q.pop_front();

		// traverse edges
		for(auto const& neighbor: e[current]) {
			if(v[neighbor - 1] == 0) { // if not yet marked
				v[neighbor - 1] = current; // mark as
				q.push_back(neighbor); // in next step
				e[neighbor].erase(current); // optimize
			}
		}
	}
	return true;
}

int main() {
	ll N, M;
	cin >> N >> M;
	deque<ll> q; // 幅優先探索キュー
	vector<ll> v(N); // 道しるべ
	unordered_map<ll, unordered_set<ll>> e; // 通路

	for(int i=1; i<=M; ++i) {
		ll Ai, Bi;
		cin >> Ai >> Bi;
		e[Ai].insert(Bi);
		e[Bi].insert(Ai);
	}

	q.push_back(1); // 入口から探索開始

	auto const& res = search(q, v, e);

	if (res) {
		cout << "Yes" << endl;
		for(int i=2; i<=N; ++i) {
			cout << v[i-1] << endl;
		}
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 30688
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int k,n;
  cin>>k>>n;
  long long int a[n],i,j=0,m,sum1=0;
  vector<long long int>b;
  for(i=0;i<n;i++)
    cin>>a[i];
    for(i=0;i<n-1;i++)
    {
        j=abs(a[i]-a[i+1]);
        b.push_back(j);
    }
   m=abs(k+a[0]-a[n-1]);
   b.push_back(m);
   sort(b.begin(),b.end());
   for(i=0;i<b.size()-1;i++)
   {
       sum1+=b[i];
   }
   cout<<sum1;


}

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

int main()
{
    int n, m; cin>>n>>m;
    if (n>m) swap(n, m);
    if (n>1)
        cout<<(n-2L)*(m-2L)<<endl;
    else 
        cout<<(m==1 ? 1 : m-2)<<endl;
}


Measured memory_bytes: 256
//
//  main.cpp
//
//
//  Created by ???????????? on 2017/10/23.
//  Copyright ?? 2017 ????????????. All rights reserved.
//

#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>


#define n_max 10000
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define INFTY 1<<20

using namespace std;

int n, color[n_max], d[n_max], p[n_max];

vector<pair<int, int> > adj[n_max];


void init(){
    int i, j, id, num, node, weight;
    scanf("%d", &n);
    
    for(i = 0; i < n; i++){
        scanf("%d %d", &id, &num);
        for(j = 0; j < num; j++){
            scanf("%d", &node);
            scanf("%d", &weight);
            adj[id].push_back(make_pair(node, weight));
        }
        color[i] = WHITE;
        d[i] = INFTY;
    }
}

void dijkstra(){
    //initializing
    d[0] = 0;
    p[0] = -1;
    
    priority_queue<pair<int,int> > PQ;
    
    PQ.push(make_pair(0, 0));
    
    int u;
    while(!PQ.empty()){
        //first weight, second idx
        pair<int, int> f= PQ.top(); PQ.pop();
        u = f.second;
        color[u] = BLACK;
        
        if(d[u] < f.first*(-1)) continue;
        
        for(int j = 0; j < adj[u].size(); j++){
            int v = adj[u][j].first;
            if(color[v] != BLACK){
                if((d[u] + adj[u][j].second) < d[v]){
                    d[v] = adj[u][j].second + d[u];
                    PQ.push(make_pair(d[v]*(-1), v));
                    color[v] = GRAY;
                }
            }
        }
    }
    for(int i = 0; i < n; i++){
        cout<<i<<" "<<d[i]<<endl;
    }
}

int main(int argc, const char * argv[]) {
    init();
    dijkstra();
    return 0;
}

Measured memory_bytes: 8124
n=int(input())
al=list(map(int,input().split()))
mod=10**9+7
t=[0]*61
for a in al:
    for i in range(61):
        if 2**i&a:
            t[i]+=1
ans=0
for i in range(61):
    if t[i]>0:
        ans+=(n-t[i])*t[i]*2**i%mod
print(ans%mod)

Measured memory_bytes: 122936
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main() {
  int n;cin >>n;
  vector<ll> a(n), sum(n+1);
  for(int i = 0; i < n; ++i)cin >>a[i];
  sort(a.begin(), a.end());
  for(int i = 0; i < n; ++i){
    sum[i+1]=sum[i]+a[i];
  }
  a.push_back(0);
  int ans = 0;
  for(int i = n; i >= 0; --i){
    if(a[i]<= 2*sum[i]){
      ++ans;
    }
    else{
      break;
    }
  }
  cout << ans << endl;
}


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

using namespace std;

struct mys{
    double lit;
    long long int price;
    long double prlit;
}temp;

bool cmp(mys &a, mys &b){
    return a.prlit<b.prlit ;
}

int main() {
    long long int arr[4] , n=0 ;
    long long int ans=0;
    vector<mys> v;
    cin >> arr[0] >> arr[1] >> arr[2] >> arr[3];

    cin >> n;
    temp.lit=.25;
    temp.price= arr[0];
    temp.prlit= 4*arr[0];
    v.push_back(temp);

    temp.lit=0.5;
    temp.prlit= 2*arr[1];
    temp.price=arr[1];
    v.push_back(temp);

    temp.lit=1;
    temp.prlit= arr[2];
    temp.price= arr[2];
    v.push_back(temp);

    temp.lit=2;
    temp.prlit= .5*arr[3];
    temp.price= arr[3];
    v.push_back(temp);

    sort(v.begin() , v.end() , cmp);

    for(int i=0; i<4; i++){
         int temprice=0;
        temprice = (n/v[i].lit);
        //cout << " t  " << v[i].lit << endl;
        ans+= temprice* (v[i].price);
        n-= v[i].lit*temprice;
        if(n==0)
            break;
    }

    cout << (ans) << endl;

    return 0;
}


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

typedef long long int int64;
typedef unsigned long long int uint64;
typedef vector<int64> vi;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef pair<int64,int64> pi; 
bool doubleSame(double a, double b)
{ const double eps = 1e-15; return ( abs(a-b)<= eps*abs(a) ); }
 
int main()
{
	int64 n,k;
	cin>>n>>k;
 
	vector<int64> h(n);
	for(int64 i = 0 ; i<n ; i++)
		cin>>h[i];
 
	vector<int64> ans(n);
	ans[0] = 0;
	ans[1] = abs(h[1]-h[0]);
 
	for(int64 i = 2 ; i<n ; i++)
	{
		ans[i] = abs(h[i]-h[i-1])+ans[i-1];
		for(int64 j = 2 ; j<=i && j<=k ; j++)
			ans[i] = min(ans[i],abs(h[i]-h[i-j])+ans[i-j]);	
	}
	cout<<ans[n-1];
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include<vector>
#include<set>
#define ll long long
using namespace std;
  
int main() {
	
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t,a,b,c,d=0,n,m,k,sum,i,j;
       string str;
     cin>>a>>b>>c>>d;
     if(c>b)
     {
     	cout<<0<<endl;
     	return 0;
	 }
	 else 
	 {
	 	sum=min(b,d);
	 	k=max(a,c);
	 }
	cout<<max(0,(sum-k))<<endl;
    
  return 0;
}


Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        String t = sc.next();
        
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < n; i++){
            sb.append(s.charAt(i)).append(t.charAt(i));
        }
        
        System.out.println(sb);
    }
}

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

int main(){
	char N[10]={'\0'};
	scanf("%s",N);
	int tmp, min = 1000;
	for(int i = 0; i <strlen(N)-2; i++ ){
		int tmp = (N[i]-'0')*100 + (N[i + 1]-'0')*10 + (N[i+2]-'0');
		tmp = abs(753-tmp);
		min = min < tmp ? min : tmp;
	}
	printf("%d\n",min);
	return 0;
}

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

#define INF INT32_MAX

int main()
{
	int V, E;
	cin >> V >> E;
	vector<vector<long long>> mat( V, vector<long long>( V, INF ) );
	for( int i = 0; i < V; i++ ) mat[i][i] = 0;
	for( int i = 0; i < E; i++ ) {
		int s, t, d;
		cin >> s >> t >> d;
		mat[s][t] = d;
	}

	for( int k = 0; k < V; k++ ) {
		for( int i = 0; i < V; i++ ) {
			if( mat[i][k] == INF ) continue;
			for( int j = 0; j < V; j++ ) {
				if( mat[k][j] == INF ) continue;
				mat[i][j] = min( mat[i][j], mat[i][k] + mat[k][j] );
			}
		}
	}
	int nega = 0;
	for( int i = 0; i < V; i++ ) {
		if( mat[i][i] < 0 ) {
			nega = 1;
			break;
		}
	}
	if( nega ) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for( int i = 0; i < V; i++ ) {
			for( int j = 0; j < V; j++ ) {
				if( j ) cout << " ";
				int d = mat[i][j];
				if( d == INF ) cout << "INF";
				else cout << d;
			}
			cout << endl;
		}
	}
}



Measured memory_bytes: 3240
INF = 10**18

N = int(input())
G = [list(map(int,input().split())) for _ in range(N)]

# warshall-floyd
dist = [G[i][:] for i in range(N)]
for k in range(N):
    for i in range(N):
        for j in range(N):
            dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j])

ans = 0
for i in range(N):
    for j in range(i+1,N):
        ans += G[i][j]

        if dist[i][j] < G[i][j]:
            print(-1)
            exit()

        for k in range(N):
            if i == k or j == k: continue
            if dist[i][j] == dist[i][k] + dist[k][j]:
                ans -= dist[i][j]
                break
        
print(ans)

Measured memory_bytes: 75984
from itertools import combinations
while 1:
    N, M= map(int,input().split())
    if N == M == 0:
        break
    else:
        li = [n + 1 for n in range(N)]
        combi = list(combinations(li,3))
        cont = 0
        for com in combi:
            if sum(com) == M:
                cont += 1
        print(cont)


Measured memory_bytes: 31428
s=raw_input()
K=input()
s=list(s)
#a-z 97-122
for i in xrange(len(s)):
    if s[i]=='a':
        continue
    if ord(s[i])+K < 123:
        continue
    else:
        K-=(123-ord(s[i]))
        s[i]='a'
if K>0:
    asc=ord(s[-1])+K%26
    s[-1]=chr(asc)
print "".join(s)


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if(a % 3 == 0) cout << "Possible" << endl;
  else if(b % 3 == 0) cout << "Possible" << endl;
  else if((a+b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}

Measured memory_bytes: 3572
//Krzysztof Boryczka
#pragma GCC optimize "O3"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int inf=0x3f3f3f3f;
const ll INF=0x3f3f3f3f3f3f3f3f;

#define FOR(i, b, e) for(int i=b; i<=e; i++)
#define FORD(i, b, e) for(int i=b; i>=e; i--)
#define SIZE(x) ((int)x.size())
#define pb push_back
#define st first
#define nd second
#define sp ' '
#define ent '\n'

const int N=82;
const int offset=13000;

bool dp[N][N][offset*2+5];
int n, m, ans=inf;
int a[N][N];

int f(int v){
	v+=offset;
	return max(0, min(offset*2+1, v));
}

void solve(){
	cin>>n>>m;
	FOR(i, 1, n) FOR(j, 1, m) cin>>a[i][j];
	FOR(i, 1, n) FOR(j, 1, m){
		int b; cin>>b;
		a[i][j]-=b;
	}
	dp[0][1][offset]=dp[1][0][offset]=1;
	FOR(i, 1, n){
		FOR(j, 1, m){
			FOR(k, -offset, offset){
				dp[i][j][k+offset]|=(dp[i-1][j][f(k-a[i][j])]|dp[i-1][j][f(k+a[i][j])]);
				dp[i][j][k+offset]|=(dp[i][j-1][f(k-a[i][j])]|dp[i][j-1][f(k+a[i][j])]);
			}
		}
	}
	FOR(k, -offset, offset){
		if(dp[n][m][k+offset]) ans=min(ans, abs(k));
	}
	cout<<ans<<ent;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	// int tt; cin>>tt;
	// FOR(te, 1, tt)
	solve();
	return 0;
}


Measured memory_bytes: 168320
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>

using namespace std;
int a[100050];
int dp[100050];
const int INF =1<<30;

int main(){
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		dp[i]=INF;
	}
	
	dp[0]=0;
	for(int i=0;i<n-1;i++){
		for(int j=1;j<=k;j++){
			if(i+j>n-1)break;
			dp[i+j]=min(dp[i+j],dp[i]+abs(a[i]-a[i+j]));	
		}
	}
	
	cout<<dp[n-1];
	
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
double PI = acos(-1);

int main() {
  int a, b, h, m;
  scanf("%d %d %d %d", &a, &b, &h, &m);
  cout << fixed << setprecision(11);
  //a=>hとmを考慮、1分で0.5度, b=>mだけ考える、1分で6度。
  double x = abs(30*h + 0.5*m - 6*m);
  double deg = x <=180? x: 360-x;
  double cosC = cos(PI*(deg)/180);
  double c = sqrt(a*a + b*b -2*a*b*cosC);
  cout << c;
}

Measured memory_bytes: 4276
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
 int x=n/100;
 int y=n%100/10;
 int z=n%10;
  if (x==7 || y==7 || z==7)
    cout << "Yes";
  if (x!=7 && y!=7 && z!=7)
    cout  << "No";
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
    string S; cin >> S;
    bool w = false, e = false, n = false, s = false;
    for (int i = 0; i < S.length(); ++i) {
        if (S[i] == 'S') s = true;
        if (S[i] == 'N') n = true;
        if (S[i] == 'W') w = true;
        if (S[i] == 'E') e = true;
    }
    if ((s == true && n == true && e == false && w == false) || (s == true && n == true && e == true && w == true) || (s == false && n == false && e == true && w == true)) printf("%s\n", "Yes");
    else printf("%s\n", "No");
}


Measured memory_bytes: 3632
import sys
from itertools import combinations

def comb_mod(n, r, MOD=10**9+7):
    if n < 0 or r < 0 or n < r:
        return 0

    factrial = [1] * (n+1)
    for k in range(1, n+1):
        factrial[k] = (factrial[k-1] * k) % MOD

    fact_inv = [1] * (n+1)
    fact_inv[n] = pow(factrial[n], MOD - 2, MOD)
    for k in range(n-1, -1, -1):
        fact_inv[k] = (fact_inv[k+1] * (k+1)) % MOD

    return (factrial[n] * fact_inv[r] * fact_inv[n-r]) % MOD


def main():
    input = sys.stdin.readline
    MOD = 10**9 + 7
    N, M, K = map(int, input().split())

    # The number of times that pieces are located on certain two tiles.
    num = comb_mod(N*M-2, K-2)

    ans = 0
    # Column-wise distance
    for i in range(M):
        ans += i * (M - i) * N**2 * num
        ans %= MOD

    # Row-wise distance
    for i in range(N):
        ans += i * (N - i) * M**2 * num
        ans %= MOD

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 19572
#pragma region Template
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(int i = 0; i < n; i++)
#define RNG(i, a, b) for(int i = a; i < b; i++)
#define RBF(i, v) for(auto& i : v)
#define ALL(x) x.begin(), x.end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;
template<typename T> using VP = vector<pair<T, T>>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }
#pragma endregion

signed main()
{
	int d, g;
	cin >> d >> g;
	vector<int> p(d), c(d);
	for (int i = 0; i < d; i++) {
		cin >> p[i] >> c[i];
	}

	// それぞれの配点の問題をコンプリートするか全く解かないかでbit全探索
	int Qnum = INF;
	for (unsigned b = 0; b < (1u << d); b++) {
		bitset<10> bit(b);
		int point = 0, Qnum_tmp = 0;
		for (int i = 0; i < d; i++) {
			if (bit[i]) {
				// コンプリートした時の得点を足す
				point += 100 * (i + 1) * p[i] + c[i];
				Qnum_tmp += p[i];
			}
		}

		// 中途半端に解くのはコンプリ―トしてない中で最高配点の問題が最善
		if (b != (1u << d) - 1u) {
			int j = d - 1;
			while (bit[j] && j > 0) { j--; }
			int pj = p[j];
			while (point < g && pj > 1) {
				point += 100 * (j + 1);
				Qnum_tmp++;
				pj--;
			}
		}

		if (point >= g) {
			Qnum = min(Qnum, Qnum_tmp);
		}
	}

	cout << Qnum << endl;
	return 0;
}


Measured memory_bytes: 3596
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    return a//gcd(a,b)*b
n=int(input())
ans=int(input())
for i in range(n-1):
    t=int(input())
    ans=lcm(ans,t)
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <algorithm>
#include <ctype.h>
#include <vector>
#include <numeric>
#include <map>
#include <queue>
#include <deque>
#include <bitset>
using namespace std;

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<ll>
#define vllll vector<vector<ll>>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

void Print(bool c)
{
    if (c)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}



int main()
{
    int n;
    cin>>n;
    char f[n][11];
    vllll p(n,vll(11));
    rep(i,0,n){
        rep(j,0,10)cin>>f[i][j];
    }
    rep(i,0,n){
        rep(j,0,11)cin>>p[i][j];
    }
    
    ll ans=-LINF;
    rep(i,1,2<<9){
        stringstream ss;
        ss << bitset<10>(i);
        string s = ss.str();
        ll sum=0;
         rep(j,0,n){
            int cnt=0;
            rep(k,0,10){
                if(f[j][k]==s[k] && s[k]=='1')cnt++;
            }
            sum+=p[j][cnt];
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}


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

int main() {
    long h, t, temp = 0, ans;
    cin >> h;
    t = h;
    while(t) {
        t /= 2;
        temp++;
    }
    ans = pow(2, temp) - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256