akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        xy: [(f64, f64); n],
    }

    let decay = 0.999;
    let mut range = 1000.0;

    let mut cx = 0.0;
    let mut cy = 0.0;

    let dist = |x1: f64, y1: f64, x2: f64, y2: f64| -> f64 {
        ((x1-x2).powi(2) + (y1-y2).powi(2)).sqrt()
    };

    let mut ans = 0.0;

    for _ in 0..100000 {
        let mut far_dir = (0.0, 0.0);
        let mut far_dist = 0.0;

        for &(x, y) in xy.iter() {
            let d = dist(x, y, cx, cy);
            if d > far_dist {
                far_dist = d;
                far_dir = (x-cx, y-cy);
            }
        }

        let fd_norm = dist(far_dir.0, far_dir.1, 0.0, 0.0);
        far_dir.0 /= fd_norm;
        far_dir.1 /= fd_norm;

        cx += far_dir.0 * range;
        cy += far_dir.1 * range;

        ans = far_dist;
        range *= decay;
    }

    println!("{:.12}", ans);
}


Measured memory_bytes: 4352
n=int(input())
s=list(input())
c=0
if n%2 != 0:
    print('No')
    exit()
else:
    for i in range(n//2):
        if s[i]!=s[i+n//2]:
            c+=1
    if c==0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b, c;
	cin >> a >> b >> c;
	if (a == b && b == c)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
# ref: https://atcoder.jp/contests/abc136/submissions/6696160
# ref: https://atcoder.jp/contests/abc136/submissions/6708692
import sys
input = sys.stdin.readline

n = int(input())
XY = sorted(list(map(int, input().split())) for _ in range(n))
X, Y = zip(*XY)
Y_rank = {z: i for i, z in enumerate(sorted(Y), 1)}

mod = 998244353


class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= i & -i
        return s

    def add(self, i, j):
        while i <= self.n:
            self.data[i] += j
            i += i & -i


po2 = [1]
for i in range(200200):
    po2.append(po2[-1] * 2 % mod)

b = BIT(n)

res = 0
for L, (x, y) in enumerate(XY):
    y = Y_rank[y]
    A = b.sum(y)
    B = L - A
    D = y - 1 - A
    C = n - 1 - A - B - D
    res += po2[n] - (po2[A+B] + po2[B+C] + po2[C+D] + po2[D+A]) + (po2[A] + po2[B] + po2[C] + po2[D]) - 1
    res %= mod
    b.add(y, 1)
print(res)


Measured memory_bytes: 122324
using System;

namespace ABC104
{
    class Program
    {
        static void Main(string[] args)
        {
            long r = Int64.Parse(Console.ReadLine());
            if (r >= 2800)
            {
                Console.WriteLine("AGC");
            }
            else if (r >= 1200)
            {
                Console.WriteLine("ARC");
            }
            else
            {
                Console.WriteLine("ABC");
            }
        }
    }
}


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

int main() {
    int A,B,C,X;
    int res=0;
    cin >> A >> B >> C >> X;
    for(int i=0;i<=A;i++){
      for(int j=0;j<=B;j++){
        for(int k=0;k<=C;k++){
            if(500*i+100*j+50*k == X) res++;
            }
        }   
    }   
    cout << res << endl;     
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
#define all(v) v.begin(),v.end()
 
int main() {
  char X,Y;
  cin>>X>>Y;
  if(X-Y==0) {
cout<<'='<<endl;
  }
  else if(X>Y) {
cout<<'>'<<endl;
  }
  else {
cout<<'<'<<endl;
  }
}

Measured memory_bytes: 3584
function main(input){
  var nums= input.split('\n')[1].split(' ');
  var cnt=0;
  while(nums.every(n => (n%2)===0)){
    cnt++;
    nums= nums.map(n => n/2);
  }
  console.log(cnt);
}
main(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 7500
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderPractice
{
    class RedScarf
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int[] b = new int[n];
            int s = 0;

            foreach(var date in a)
            {
                s ^= date;
            }

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

            foreach(var date in b)
            {
                Console.Write($"{date} ");
            }
            Console.WriteLine();
        }
    }
}


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

int main() {
  int n, last = 0, min = 0;
  char white = '.', black = '#';
  string s;
  cin >> n >> s;

  for (int i = 0; i < s.size(); i++) if (s.at(i) == white) last++;
  min = last;
  for (int i = 1; i <= s.size(); i++) {
    s.at(i - 1) == black ? last++ : last--;
    if (min > last) min = last;
  }
  cout << min << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;

ll sum(ll n) {
  return n*(n+1)/2;
}

int main() {
  int a, b; cin >> a >> b;
  
  repi(i,2,999) {
    if (b-a == i) {
      cout << sum(i) - b << endl; 
      return 0;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

using namespace std;

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

const ll mod = 1000000007;
const int inf = 1e9;
const long long INF = 1LL << 60;


int dp[11][100100];

int main()
{
    int a,b,m;
    cin >> a >> b >> m;
    int am[a],bm[b];
    for(int i = 0; i < a; i++){
        cin >> am[i];
    }
    for(int i = 0; i < b; i++){
        cin >> bm[i];
    }
    int x[m],y[m],c[m];
    for(int i = 0; i < m; i++){
        cin >> x[i] >> y[i] >> c[i];
        x[i]--; y[i]--;
    }
    vector<int> p;
    for(int i = 0; i < m; i++){
        p.push_back(am[x[i]] + bm[y[i]] - c[i]);
    }
    sort(am,am+a);
    sort(bm,bm+b);
    p.push_back(am[0] + bm[0]);
    sort(p.begin(),p.end());
    cout << p[0] << endl;

}


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

using namespace std;
typedef long long ll;
#define Inf 1 << 20
#define MInf -(1 << 20)


#define REP(n) for(int i = 0;i < (int)(n);i++)
#define rep(i,n) for(int i = 0;i < (int)(n);i++)
#define Rep(i,n,m) for(int i = (int)(n); i < (int)(m);i++)
#define rrep(i,n) for(int i = (int)(n - 1); i > -1;i--)
#define RRep(i,n,m) for(int i = (int)(n - 1); i > (int)(m);i--)
#define trav(a, x) for(auto& a : x)

#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V))
#define REVERSE(V) reverse(ALL(V))
#define RSORT(V) SORT(V);REVERSE(V)


#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define yes(n) cout << ((n) ? "yes" : "no") << endl;




int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    int count = 1;
    rep(i,N)
    {
        cin >> H.at(i);
    }
    bool is = true;
    Rep(i,1,N)
    {
        is = true;
        Rep(j,0,i)
        {
            if(H[j] > H[i])
                is = false;
        }
        if(is)
            count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b && b==c){
		printf("1\n");
	}
	else if(a==b || a==c || b==c){
		printf("2\n");
	}
	else{
		printf("3\n");
	}
	return 0;
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define VEC vector

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;
typedef vector<int>				Vint;
typedef vector<Vint>			VV;

template<typename T>string join(const v(T)&v)
{stringstream s;REP(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define MAX 		400010

const ll LINF = (ll)9e18+7;		//
const int INF = 100100100;			//2,147,483,647 (Max int)
const ll MOD = 1e9+7;
// テンプレ終了
//====================================================================//

// int DP[MAX];


//
int main(){
	ll X;
	cin >> X;

	REP(i100,(int)X/100+1){
		ll a1 = X - i100 * 100;
		REP(i101,(int)a1/101+1){
			ll a2 = a1 - i101 * 101;
			REP(i102,(int)a2/102+1){
				ll a3 = a2 - i102 * 102;
				REP(i103,(int)a3/103+1){
					ll a4 = a3 - i103 * 103;
					REP(i104,(int)a4/104+1){
						ll a5 = a4 - i104 * 104;
						if(a5 < 0)continue;
						if(a5%105 == 0){cout << "1" << endl;return 0;}
						
					}
				}
			}
		}
	}
	cout << "0" << endl;
	return 0;
}




Measured memory_bytes: 256
import queue

k = int(input())

q = queue.Queue()

for i in range(1, 10):
    q.put(i)

for i in range(1, int(1e5 + 1)):
    n = q.get()
    if i == k:
        print(n)
        exit()
    if n % 10 != 0:
        q.put(n * 10 + (n - 1) % 10)
    q.put(n * 10 + n % 10)
    if n % 10 != 9:
        q.put(n * 10 + (n + 1) % 10)

Measured memory_bytes: 12964
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = in.nextInt();
        int w = in.nextInt();
        int[] ws = new int[n];
        int[] vs = new int[n];
        for (int i = 0; i < n; i++) {
            ws[i] = in.nextInt();
            vs[i] = in.nextInt();
        }
        long[][] dp = new long[n + 1][w + 1];

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= w; j++) {
                if (j - ws[i - 1] >= 0) {
                    dp[i][j] = Math.max(dp[i - 1][j], dp[i - 1][j - ws[i - 1]] + vs[i - 1]);
                } else {
                    dp[i][j] = dp[i - 1][j];
                }
            }
        }
        System.out.println(dp[n][w]);
    }
}


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

struct UnionFind
{
  vector<int64_t> data;

  UnionFind(int sz)
  {
    data.assign(sz, -1);
  }

  bool unite(int x, int y)
  {
    x = find(x), y = find(y);
    if(x == y) return(false);
    if(data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return(true);
  }

  int find(int k)
  {
    if(data[k] < 0) return(k);
    return(data[k] = find(data[k]));
  }

  int64_t size(int k)
  {
    return(-data[find(k)]);
  }
};

typedef UnionFind UF;

int main(){
  int64_t N,M;
  cin>>N>>M;
  vector<pair<int,int>> p(M);
  for(int i=0;i<M;++i){
    int a,b;
    cin>>a>>b;
    --a,--b;
    p[i]=make_pair(a,b);
  }

  UF uf(N);
  vector<int64_t> ans(M+1);
  ans[M]=N*N-N;
  for(int i=M-1;i>=0;--i){
    int a=p[i].first,b=p[i].second;
    if(uf.find(a)==uf.find(b)) ans[i]=ans[i+1];
    else{
      ans[i]=ans[i+1]-2*uf.size(a)*uf.size(b);
      uf.unite(a,b);
    }
  }

  for(int i=1;i<=M;++i) cout<<ans[i]/2<<endl;
}

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

const int N = 20007;

int main() {
    int dp[N];
    memset(dp, -1, sizeof(dp));
    int h, n;
    cin >> h >> n;   
    vector<int> a(n), b(n);
    for(int i=0; i<n; i++)
        cin >> a[i] >> b[i];

    dp[0] = 0;
    for(int i=0; i<n; i++) {
        for(int j = a[i]; j<N; j++) {
            if(dp[j-a[i]] == -1)
                continue;
            if(dp[j] == -1)
                dp[j] = dp[j-a[i]] + b[i];
            else
                dp[j] = min(dp[j], dp[j-a[i]] + b[i]);
        }
    }
    int ans = INT_MAX;
    for(int i=h; i<N; i++) {
        if(dp[i] != -1) {
            ans = min(ans, dp[i]);
        }
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 384
// C++ implementation of the approach 
#include <bits/stdc++.h> 
using namespace std; 
using ll = long long;
// Function to return length 
// of the resulatant number 
ll numLen(ll K) 
{ 

	// If K is a multiple of 2 or 5 
	if (K % 2 == 0 || K % 5 == 0) 
		return -1; 

	ll number = 0; 

	ll len = 1; 

	for (len = 1; len <= K; len++) { 

		// Instead of generating all possible numbers 
		// 1, 11, 111, 111, ..., K 1's 
		// Take remainder with K 
		number = (number * 10 + 7) % K; 

		// If number is divisible by k 
		// then remainder will be 0 
		if (number == 0) 
			return len; 
	} 

	return -1; 
} 

// Driver code 
int main() 
{ 
	ios::sync_with_stdio(0);cin.tie(0);
	ll k;
	cin >> k;
	cout << numLen(k);
} 


Measured memory_bytes: 3644
#include<iostream>
using namespace std;
#include<stdio.h>
int main(){
	for(;;){
		int a,b=0,c=0;
		cin>>a;
		if(a==0)break;
		b=1000-a;
		c=(b/500)+((b%500)/100)+(((b%500)%100)/50)+((((b%500)%100)%50)/10)+(((((b%500)%100)%50)%10)/5)+(((((b%500)%100)%50)%10)%5);
		cout<<c<<endl;
	}
	return 0;
}

Measured memory_bytes: 3068
def slove():
    import sys
    input = sys.stdin.readline
    w, a, b = list(map(int, input().rstrip('\n').split()))
    if a + w < b:
        print(abs(a + w - b))
    elif b + w < a:
        print(abs(b + w - a))
    else:
        print(0)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 38256
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

template <std::size_t MOD>
class ModuloInteger
{
public:
    ModuloInteger(const std::size_t init)
        : value(init)
    {
    }

    ModuloInteger operator+(const ModuloInteger& value);
    void operator+=(const ModuloInteger& value);

    ModuloInteger operator-(const ModuloInteger& value);
    void operator-=(const ModuloInteger& value);

    ModuloInteger operator*(const ModuloInteger& value);
    void operator*=(const ModuloInteger& value);

    std::size_t value;
};

template <std::size_t MOD>
ModuloInteger<MOD> ModuloInteger<MOD>::operator+(const ModuloInteger& value)
{
    return (this->value + value.value) % MOD;
}

template <std::size_t MOD>
void ModuloInteger<MOD>::operator+=(const ModuloInteger& value)
{
    this->value = (this->value + value.value) % MOD;
}

template <std::size_t MOD>
ModuloInteger<MOD> ModuloInteger<MOD>::operator-(const ModuloInteger& value)
{
    return (this->value + MOD - value.value) % MOD;
}

template <std::size_t MOD>
void ModuloInteger<MOD>::operator-=(const ModuloInteger& value)
{
    this->value = (this->value - value.value) % MOD;
}

template <std::size_t MOD>
ModuloInteger<MOD> ModuloInteger<MOD>::operator*(const ModuloInteger& value)
{
    return (this->value * value.value) % MOD;
}

template <std::size_t MOD>
void ModuloInteger<MOD>::operator*=(const ModuloInteger& value)
{
    this->value = (this->value * value.value) % MOD;
}

int main()
{
    int n, k;
    cin >> n >> k;
    constexpr size_t MOD = 1000000007;
    vector<size_t> as(n);
    for (auto& v : as)
    {
        cin >> v;
    }

    vector<vector<ModuloInteger<MOD>>> dp(n + 1, vector<ModuloInteger<MOD>>(k + 1, 0));

    fill(dp[0].begin(), dp[0].end(), 1);

    for (int i = 1; i <= n; i++)
    {
        for (int j = 0; j <= k; j++)
        {
            dp[i][j] = (as[i - 1] < j ? (dp[i - 1][j] - dp[i - 1][j - as[i - 1] - 1]) : dp[i - 1][j]);
            if (j > 0 && i < n)
            {
                dp[i][j] += dp[i][j - 1];
            }
        }
    }
    cout << dp[n][k].value << endl;
}

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

int main() {
  int h, w;
  while (cin >> h >> w, (h | w) != 0) {
    for (int i = 0; i < h; i++) {
      for (int j = 0; j < w; j++) {
        if ((i + j) % 2 == 0) cout << "#";
        else cout << ".";
      }
      cout << "\n";
    }
    cout << "\n";
  }
  return 0;
}


Measured memory_bytes: 3100
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
ll gcd(ll a, ll b)
{
	for (;;)
	{
		if (a < b)swap(a, b);
		a %= b;
		if (a == 0)return b;
	}
}
bool dp[6333][3333];
int main()
{
	int a, b, c, d, e, f;
	scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f);
	dp[0][0] = true;
	double maxi = -1;
	int rx = 0, ry = 0;
	for (int i = 0; i <= f; i++)
	{
		for (int j = 0; j <= i; j++)
		{
			if (!dp[i][j])continue;
			dp[i + 100 * a][j] = true;
			dp[i + 100 * b][j] = true;
			dp[i + c][j + c] = true;
			dp[i + d][j + d] = true;
			if (i != j&&j * 100 <= (i - j)*e)
			{
				if (maxi<double(j) / double(i))maxi = double(j) / double(i), rx = i, ry = j;
			}
		}
	}
	printf("%d %d\n", rx, ry);
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */
int main(){
    string s; cin >> s;
    if(s == "AAA" || s == "BBB") out("No");
    else out("Yes");
}

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

int main() {
  int r,c;
  cin>>r>>c;
  vector<vector<char>> a(r,vector<char>(c));
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      cin>>a.at(i).at(j);
    }
  }
  vector<vector<int>> b(r,vector<int>(c));
  vector<int> dx={1,0,-1,0};
  vector<int> dy={0,1,0,-1};
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      b.at(i).at(j)=114514;
    }
  }
  queue<P> q;
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      if(a.at(i).at(j)=='#'){
        q.push(P(i,j));
        b.at(i).at(j)=0;
      }
    }
  }
  while(q.size()){
    P p=q.front();
    q.pop();
    for(int i=0;i<4;i++){
      int nx=p.first+dx.at(i);
      int ny=p.second+dy.at(i);
      if(0<=nx&&nx<r&&0<=ny&&ny<c&&a.at(nx).at(ny)=='.'&&b.at(nx).at(ny)==114514){
        q.push(P(nx,ny));
        b.at(nx).at(ny)=b.at(p.first).at(p.second)+1;
      }
    }
  }
  int ans=0;
  for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
      ans=max(ans,b.at(i).at(j));
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 13328
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int a,b;
    int i;
    cin>>a>>b;
    if(a>b){
        rep(i,a){
            cout<<b;
        }
    }else{
        rep(i,b){
            cout<<a;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll H,W,N;
    cin >> H >> W >> N;
    map<P,int> mp;
    rep(i,0,N){
        int a,b;
        cin >> a >> b;
        a--,b--;
        int dx[] = {-1,-1,-1,0,0,0,1,1,1};
        int dy[] = {-1,0,1,-1,0,1,-1,0,1};
        rep(j,0,9){
            int ny = a + dy[j];
            int nx = b + dx[j];
            if(ny < 1 || ny >= H-1 || nx < 1 || nx >= W-1)continue;
            mp[P(ny, nx)]++;
        }
    }
    ll cnt[10] = {}, sum = 0;
    for(auto p:mp){
        //cout << p.first.first << " " << p.first.second << endl;
        cnt[p.second]++;
    }
    rep(i,0,10)sum += cnt[i];
    cnt[0] = (H-2) * (W-2) - sum;
    rep(i,0,10){
        cout << cnt[i] << endl;
    }
}

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

#define int long long
#define otp(n) cout << n;
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define ctv(v) rep(i,(v).size()) otp(v[i]) cte
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define repv(i,v) for(int i=0;i<(v).size();i++)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int n,k,ans;

main() {
    cin >> n >> k;
    ans = k;
    k--;
    rep(i,n-1) ans*=k;
    ct(ans)
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    string s;
    int n,k,c=0;
    vector<int> a;
    cin >> n >> k >> s;
    rep(i,n){
        int j = i;
        while(s[j+1]==s[j]&&j+1<n) j++;
        a.push_back(j-i+1);
        i = j;
    }
    reverse(a.begin(),a.end());
    if(s[0]=='0') a.push_back(0);
    reverse(a.begin(),a.end());
    if(s[n-1]=='0') a.push_back(0);
    vector<int> b(a.size()+1);
    rep(i,a.size()) b[i+1] = b[i] + a[i];
    for(int i=0;i<a.size();i+=2){
        int left = i;
        int right = min(i+2*k+1,(int)a.size());//累積和としての左右
        c = max(c,b[right]-b[left]);
    }
    cout << c << endl;
}

Measured memory_bytes: 1272
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

#define bzero(m)  memset(m,0,sizeof(m))
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

typedef unsigned long long u64;
typedef long long i64;

int d(vector<int> &h, int l, int r){
        int mi = 1000000;

//        debug(l);
//        debug(r);
//        debug(h[0]);
//        debug(h[1]);
//        debug(h[2]);
//        debug(h[3]);
        if (l == r) return 0;

        for(int i=l; i<r; i++){
                if (h[i] == 0) {
                        if (i==l)
                                return d(h, l+1, r);

                        return d(h, l, i) + d(h, i, r);
                }

                mi = min(mi, h[i]);
        }

        for(int i=l; i<r; i++){
                h[i] -= mi;
        }

        return mi + d(h, l, r);
}


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

        int n;
        vector<int> h;

        cin >> n;
        REP(i, n) {
                int tmp;
                cin >> tmp;
                h.push_back(tmp);
        }

        cout << d(h, 0, n) << endl;


        return 0;
}


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

int main() {
  int h, n, a, x = 0;
  cin >> h >> n;
  for (int i = 0; i < n; i ++) {
    cin >> a;
    x += a;
  }
  if (h <= x) {
    cout << "Yes" << endl;
  }
  else if (h > x) {
    cout << "No" << endl;
  }
}  

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

int a[100000][3];

int main()
{
	int f=1,i,j,n;
	cin>>n;
	
	for(i=0;i<n;i++)
	{
		cin>>a[i][0]>>a[i][1]>>a[i][2];
		if((a[i][2]+a[i][1]>a[i][0])||a[i][0]%2!=(a[i][1]+a[i][2])%2)
			f=0;
	}
	
	if(f==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    int N, K;
    scanf("%d %d", &N, &K);
    
    // 2. ボールの塗り方としてあり得るもの.
    // -> 隣り合ったボールは別の色で塗る.
    int ans = K;
    rep(i, N - 1) ans *= (K - 1);
    
    // 3. 出力.
    printf("%d\n", ans);
    return 0;
    
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int digit(int n) {
  int res = 0;
  while(n >= 1) {
    res += (n % 10);
    n /= 10;
  }
  return res;
}

int main() {
  int M; cin >> M;
  cout << 24 + (24 - M) << endl;
}

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

# 10^(N-1)から10^Nの数を順に調べる
# N=1の場合のみ、0から10であることに注意
if N == 1:
  a, b = 0, 10
elif N >= 2:
  a, b = 10**(N-1), 10**N

ans = -1
for i in range(a, b):
  tmp = str(i)
  flag = True
  for j in range(M):
    if tmp[arr[j][0]-1] != str(arr[j][1]):
      flag = False
  if flag:
    ans = i
    break

print(ans)

Measured memory_bytes: 9144
// https://atcoder.jp/contests/agc046/tasks/agc046_a
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    int dg = 0;
    REP(i, 361) {
        dg = (dg + N) % 360;
        if (dg == 0) {
            cout << i + 1 << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3632
use proconio::input;
use std::cmp::max;

fn main() {
    input! {
        s: String,
    }

    let mut res = 0;
    for i in 0..s.len() {
        for j in i + 1..s.len() + 1 {
            let mut f = true;
            for k in i..j {
                f = f
                    && match &s.chars().nth(k).unwrap() {
                        'A' => true,
                        'T' => true,
                        'G' => true,
                        'C' => true,
                        _ => false,
                    }
            }
            if f {
                res = max(res, j - i);
            }
        }
    }
    println!("{}", res);
}


Measured memory_bytes: 2152
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

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

P a[100001]={};
ll b[100001]={};
vector<int> v[100001];
int n,m;


int main() {
	cin>>n;


	for(int i=1;i<n+1;i++){
		cin>>a[i].first;
		a[i].second=i;
	}
	sort(a,a+n+1);
	ll t=0;
	int p1=n+1;
	for(ll i=n;i>0;i--){
		t+=(ll)a[i].first;
		if(a[i].first!=a[i-1].first){
			p1=min(p1,a[i].second);
			b[p1]+=t-(n+1-i)*(a[i-1].first);
			t=(n+1-i)*(a[i-1].first);
		}
	}

	for(int i=1;i<n+1;++i)cout<<b[i]<<endl;
	return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define endl "\n"
#define ll long long int
#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 f first
#define s second

using namespace std;
int main()
{
	std::ios::sync_with_stdio(false);
	string n;
  cin>>n;
  int ans;
  int sum = 0;
  for(auto i:n){
    sum+= i-'0';
  }
  if(sum%9 == 0)  cout<<"Yes"<<endl;
  else  cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 3792
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

// main に書くと手元の環境だと Stack Overflow する
int P[100005], Y[100005];
vector<int> vec[100005];

int main() {
    int N, M;

    cin >> N >> M;

    for (int i = 0; i < M; i++) {
        int p, y;
        cin >> p >> y;
        P[i] = p; Y[i] = y;
        vec[p].push_back(y);
    }

    for (int i = 0; i < N; i++) {
        sort(vec[i+1].begin(), vec[i+1].end());
    }

    for (int i = 0; i < M; i++) {
        printf("%06d", P[i]);
        printf("%06d\n", lower_bound(vec[P[i]].begin(), vec[P[i]].end(), Y[i]) - vec[P[i]].begin()+1);
    }

    return 0;
}


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

const ll mod=1e9+7;

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

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

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

    int n;
    cin>>n;
    vector<int>p(n),q(n),a;
    rep(i,n)cin>>p[i];
    rep(i,n)cin>>q[i];
    a=p;
    sort(a.begin(),a.end());
    int i=0;
    if(p==q){
        cout<<0<<endl;
        return 0;
    }
    do{
        if(p==a||q==a){
            if(i){
                cout<<i-1<<endl;
                return 0;
            }else i=1;
        }
        if(i)i++;
    }while(next_permutation(a.begin(),a.end()));

}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
using namespace std;
int nib(int );
int n,A[100000];
int main()
{
	int i,a,b,v,t=0,c;
	cin >>n;
	for(i=0;i<n;i++) {
		cin >> A[i];
	}
	cin>>v;
	for(i=0;i<v;i++){
		cin >> c;
		if(nib(c)) t++;
	}
	cout << t<<endl;
	return 0;
}
int nib(int c)
{
	int mid,l=0,r=n;
	while(l<r){
		mid=(l+r)/2;
		if(A[mid]==c)return 1;
		if(A[mid]>c) r=mid;
		else if(A[mid]<c)l=mid+1;
	}
	return 0;
}

Measured memory_bytes: 1548
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
bool f[100];
int n;
int tr[100];


int trmin(){
  int res=10000,resi;
  for(int i=0;i<n;i++)
    if(f[i]==0 && tr[i]<res) res = tr[i],resi=i;
  return resi;
}


int main (){

  int mp[100][100];

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

  for(int i=0;i<n;i++) f[i]=0;
  for(int i=0;i<n;i++) tr[i]=10000;
  tr[0] = 0;
  int trsum=0;

  for(int k=0;k<n;k++){
    int r=trmin();
    f[r]=1;
    trsum+=tr[r];

    for(int i=0;i<n;i++) 
      if(mp[r][i]!=-1)
	tr[i] = min(tr[i],mp[r][i]);
  }
  cout<<trsum<<endl;

  return 0;
}

Measured memory_bytes: 1196
import scala.math._

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val list = List.fill(3)(sc.nextInt)
//  val a, b, c = sc.nextInt

  val ans = list.distinct.find(x => list.count(y => y == x) == 1).head

  println(ans)

  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

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

#define ll long long

using namespace std;

int mod = (int)1e9 + 7;

int add(int a, int b) {
	return (a + b) % mod;
}

int dp[101][(int)1e5 + 1];
int n, k;

main() {
	scanf("%d %d", &n, &k);
	dp[0][k] = 1;
	for (int i = 1, x; i <= n; i++) {
		scanf("%d", &x);
		int cur = 0;
		for (int j = k; j >= 0; j--) {
			cur = add(cur, dp[i - 1][j]);
			if (j + x + 1 <= k) {
				cur = add(cur, mod - dp[i - 1][j + x + 1]);
			} 
			dp[i][j] = cur;
		}
	}
	cout << dp[n][0];
}


Measured memory_bytes: 39296
#include <iostream>
#include <vector>
#include <queue>
#define int long long
#define INF 1e+18
using namespace std;
 
int h,w,n,x[100000],y[100000],a[100000],b[100000],c[100000];
bool used[100000] = {};
vector<int> numx[100000],numy[100000];
 
signed main(){
	cin >> h >> w >> n;
	for(int i = 0;i < h;i++) x[i] = INF;
	for(int i = 0;i < w;i++) y[i] = INF;
	for(int i = 0;i < n;i++){
		cin >> a[i] >> b[i] >> c[i]; a[i]--;b[i]--;
		numx[a[i]].push_back(i);
		numy[b[i]].push_back(i);
	}
	for(int i = 0;i < n;i++){
		int mix = INF,miy = INF;
		if(used[i]) continue;
		used[i] = true;
		x[a[i]] = 0;
		queue<int> que;
		que.push(i);
		while(!que.empty()){
			int p = que.front();que.pop();
			if(x[a[p]] == INF) x[a[p]] = c[p] - y[b[p]];
			else if(y[b[p]] == INF) y[b[p]] = c[p] - x[a[p]];
			else if(x[a[p]] + y[b[p]] != c[p]){
				cout << "No" << endl;
				return 0;
			}
			mix = min(mix,x[a[p]]);
			miy = min(miy,y[b[p]]);
			for(int to : numx[a[p]]){
				if(!used[to]){
					used[to] = true;
					que.push(to);
				}
			}
			for(int to : numy[b[p]]){
				if(!used[to]){
					used[to] = true;
					que.push(to);
				}
			}
			numx[a[p]].clear();
			numy[b[p]].clear();
		}
		if(mix + miy < 0){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 15232
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hope the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 200010;

int a[MAXN];
ll f[MAXN][2][2];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri, o = 0, t = 1;
	ll inf = 1LL << 62;
	for(int i = 1; i <= n; i++) {
		a[i] = ri;
		for(int x = 0; x < 2; x++)
			for(int y = 0; y < 2; y++)
				f[i][x][y] = -inf;
	}
	for(int i = 1; i <= n; i++) {
		chkmax(f[i][1][0], max(f[i - 1][0][0], f[i - 1][0][1]));
		chkmax(f[i][1][1], max(f[i - 1][0][0], f[i - 1][0][1]));
		if(i > 1) {
			for(int t = 0; t < 2; t++) {
				chkmax(f[i][t][0], f[i - 2][t][0] + a[i - 1]);
				chkmax(f[i][t][1], max(f[i - 2][t][0], f[i - 2][t][1]) + a[i]);
			}
		}
	}
	if(n & 1) cout << max(f[n][1][0], f[n][1][1]) << endl;
	else cout << max(f[n][0][0], f[n][0][1]) << endl;
	return 0;
}

Measured memory_bytes: 10908
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;
int main() {
	string s;
	cin >> s;
	int lo = 0;
	int hi = s.length()-1;
	int cnt = 0;
	while(lo < hi) {
		if(s[lo] != s[hi]) cnt++;
		lo++;
		hi--;
	}
	cout << cnt << endl;
	return 0;
}

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

int main(void)
{
  string big, little;
  cin >> big >> little;
  int ans = 1e9;
  for (int i = 0; i < big.size(); i++)
  {
    if (i + little.size() > big.size()) continue;
    int tmp = 0;
    for (int j = 0; j < little.size(); j++)
    {
      if (big[i + j] != little[j]) tmp++;
    }
    ans = min(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <bitset>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath> // 変数名にy1が使えなくなるかも…。
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>

typedef __int128_t int128_t;
std::istream &operator>>(std::istream& input, int128_t& value) { // int128_tの入力。入力が64bitに収まる前提。
    long long tmp; input >> tmp; value = tmp;
    return input;
}
std::ostream &operator<<(std::ostream& output, const int128_t value) { // int128_tの出力。出力が64bitに収まる前提。
    output << (long long)value;
    return output;
}

int128_t cal_mod(const int128_t n, const int128_t mod) {
    // n % modを計算する。ただしmod <= 0 ならば何もしない。nが負の場合、正にして補正する。
    if (mod <= 0) {
        return n;
    } else if (0 <= n) {
        return n % mod;
    } else {
        int128_t tmp = (-n) / mod + 1;
        return (n + tmp * mod) % mod;
    }
}

int128_t pow_mod(int128_t x, int128_t n, const int128_t mod) {
    // 累乗の計算。mod <= 0ならば余りの計算は行わない。
    int128_t ret = 1;
    while (n > 0) {
        if (n & 1) { ret = cal_mod(ret * x, mod); }
        x = cal_mod(x * x, mod);
        n = (n >> 1);
    }
    return ret;
}

class Combi_Num {
    // 「組み合わせ数 % 素数」を、前処理を行ったうえでO(1)で求める。modは32bitに収まることが前提。
    public:
    int128_t mod;
    std::vector<int128_t> factorial, factorial_inv, inv;
    Combi_Num() {}
    Combi_Num(const int n, const int128_t mod_in) {
        mod = mod_in;
        factorial.resize(n+1, 0);
        factorial_inv.resize(n+1, 0);
        inv.resize(n+1, 0);
        factorial[0] = 1;
        factorial_inv[0] = 1;
        inv[0] = 1;
        for (int i = 1; i <= n; i++) {
            factorial[i] = (factorial[i-1] * i) % mod;
            inv[i] = pow_mod(i, mod - 2, mod);
            factorial_inv[i] = (factorial_inv[i-1] * inv[i]) % mod;
        }
    }

    int128_t combi(const int n, const int r) {
        return (factorial[n] * ((factorial_inv[r] * factorial_inv[n-r]) % mod)) % mod;
    }

    int128_t perm(const int n, const int r) {
        return (factorial[n] * factorial_inv[n-r]) % mod;
    }
};

const int MOD = 1e9 + 7;
const int MAX_N = 1000010;
int128_t N, H, D;

Combi_Num cn = Combi_Num(MAX_N, MOD);

int128_t dp[MAX_N], dp_ac[MAX_N];

int main(int argc, char **argv) {
    std::cin >> N >> H >> D;

    int128_t coeff = 0;
    for (int i = 1; i <= N; i++) {
        coeff = (coeff + cn.factorial[i]) % MOD;
    }

    dp[0] = cn.factorial[N];
    dp_ac[0] = dp[0];

    //std::cout << dp[0] << " " << dp_ac[0] << std::endl;

    for (int i = 1; i <= H; i++) {
        int128_t tmp = dp_ac[i-1];
        if (0 < i - D) {
            tmp = cal_mod(tmp - dp_ac[i - D - 1], MOD);
        }
        if (i == H) {
            dp[i] = tmp;
        } else {
            dp[i] = (tmp * coeff) % MOD;
        }
        dp_ac[i] = (dp_ac[i-1] + dp[i]) % MOD;
    }

    std::cout << dp[H] << std::endl;
    

    return 0;
}

Measured memory_bytes: 78336
#include <stdio.h>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	int n;
	int bango,meter,taiju;
	int risoban;
	double riso;
	double riri;
	double BMI;

	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		}
		for (int i = 0; i < n; i++) {
			cin >> bango >> meter >> taiju;
			BMI = (double)taiju / ((double)pow(meter,2) / 10000.0);
			if (i == 0) {
				risoban = bango;
				if (BMI < 22.0) {
					riso = 22.0 - BMI;
				} else {
					riso = BMI - 22.0;
				}
			} else {
				riri = BMI - 22.0;
				if (riri < 0) {
					riri = -riri;
				}
				if (riri < riso) {
					riso = riri;
					risoban = bango;
				}
			}
		}
		cout << risoban << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
 }
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  vvll dp(65,vll(2,-1));
  dp[0][0]=0;
  rep(i,60){
    ll mask=1LL<<(60-i-1);
    ll cu1=0;
    rep(j,n)if(a[j]&mask) cu1++;
    ll cost0=mask*cu1;
    ll cost1=mask*(n-cu1);
    if(dp[i][0]!=-1){
      if(k&mask){
        dp[i+1][0]=max(dp[i+1][0],dp[i][0]+cost1);
      }
      else{
        dp[i+1][0]=max(dp[i+1][0],dp[i][0]+cost0);
      }
    }
    if(dp[i][0]!=-1){
      if(k&mask){
        dp[i+1][1]=max(dp[i+1][1],dp[i][0]+cost0);
      }
    }
    if(dp[i][1]!=-1){
      dp[i+1][1]=max(dp[i+1][1],dp[i][1]+max(cost1,cost0));
    }
  }
  COUT(max(dp[60][0],dp[60][1]));
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i, n) for (long long i = 0; i < (int)(n); i++)
#define sum(a) accumulate(a.begin(),a.end(),0LL)
#define put(i) cout<<fixed<<i<<endl
using namespace std;
using ll = long long;

int main(){
    ll n; cin >> n;
    vector<ll> a(n); rep(i,n) cin >> a[i];

    //ll n = 1e5; vector<ll> a(1e5,1e9);
    
    ll mod = ll(1e9+7);

    ll suma = 0;
    for(long long i = 0; i < n; i++){
        suma += a[i];
    }

    
    ll ans = 0;
    for(long long j = 0; j < n-1; j++){
        suma -= a[j];
        ans = ans + (suma % mod * a[j]) % mod;
    }
    ans %= mod;
    put(ans);
}

Measured memory_bytes: 4824
#include <iostream>
#include <vector>
#include <limits>

using namespace std;


int main(int argc, char *argv[]) {
	int N, M;
	cin >> N >> M;

	vector<long> d(N);
	vector<vector<pair<int, long>>> es(N);

	for (int i = 0; i < M; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		es[a-1].push_back(make_pair(b-1, -c));
	}

	for (int i= 0; i < N; i++) d[i] = numeric_limits<long>::max();
	d[0] = 0;

	for (int i = 0; i < N - 1; i++) {
		for (int u = 0; u < N; u++) {
			for (auto &e : es[u]) {
				auto v = e.first;
				auto c = e.second;

				if (d[u] == numeric_limits<long>::max()) continue;
				if (d[v] > d[u] + c) d[v] = d[u] + c;
			}
		}
	}

	vector<bool> neg(N);
	for (int i = 0; i < N; i++) {
		for (int u = 0; u < N; u++) {
			for (auto &e : es[u]) {
				auto v = e.first;
				auto c = e.second;

				if (d[u] == numeric_limits<long>::max()) continue;
				if (d[v] > d[u] + c) {
					d[v] = d[u] + c;
					neg[v] = true;
				}
				if (neg[u]) neg[v] = true;
			}
		}
	}

	if (neg[N-1]) cout << "inf" << endl;
	else cout << -d[N-1] << endl;

	return 0;
}

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

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

  if(A%3==0 || B%3==0 || (A+B)%3 == 0){
    cout << "Possible" << endl;
  }else{
    cout << "Impossible" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
using namespace std;
 
int main() {
 string S,b;
 int K,a;
 cin>>K;
 cin>>S;
 a=S.size();
 if(a<=K){
   cout<<S<<endl;
 }
  else if(a>K){
    b=S.substr(0,K);
    cout<<b+"..."<<endl;
  }
}
  

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

const int N = 1e5 + 7;
const double inf = 1e18;

struct Point {
	double x, y;
	int k1, k2;
} p[N];

int n;

double check(double mid) {
	double xmx = -inf, xmn = inf, ymx = -inf, ymn = inf;
	for (int i = 0; i < n; i++) {
		xmx = max(xmx, p[i].x + p[i].k1 * mid);
		xmn = min(xmn, p[i].x + p[i].k1 * mid);
		ymx = max(ymx, p[i].y + p[i].k2 * mid);
		ymn = min(ymn, p[i].y + p[i].k2 * mid);
	}
	return (xmx - xmn) * (ymx - ymn);
}

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		char s[10];
		double x, y;
		scanf("%lf%lf%s", &x, &y, s);
		p[i].x = x, p[i].y = y;
		if (s[0] == 'R') p[i].k1 = 1;
		else if (s[0] == 'L') p[i].k1 = -1;
		else if (s[0] == 'U') p[i].k2 = 1;
		else p[i].k2 = -1;
	}
	double l = 0, r = 1e9;
	double ans = inf;
	for (int i = 0; i < 200; i++) {
		double ll = l + (r - l) / 3, rr = r - (r - l) / 3;
		double temp1 = check(ll), temp2 = check(rr);
		ans = min(ans, min(temp1, temp2));
		if (temp1 > temp2) l = ll;
		else r = rr;
		
	}
	printf("%.15f\n", ans);
	return 0;
}

Measured memory_bytes: 2560