akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long 

const int mod = 1e9 + 7;

ll quick_pow(ll a,ll b,ll mod)
{
    ll ans=1;
    while(b)
    {
        if(b&1) ans=(ans*a)%mod;
        a=(a*a)%mod;
        b>>=1;
    }
    return ans;
}

ll inv(ll x, ll mod)//x关于p的逆元，p为素数
{
    return quick_pow(x, mod - 2, mod);
}

ll C(ll n, ll m, ll mod)//组合数C(n, m) % p
{
    if(m > n)return 0;
    ll up = 1, down = 1;//分子分母;
    for(int i = n - m + 1; i <= n; i++)up = up * i % mod;
    for(int i = 1; i <= m; i++)down = down * i % mod;
    return up * inv(down, mod) % mod;
}

int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	ll x,y; cin >> x >> y;
	if((2 * x - y) % 3 || (2 * y - x) % 3) {
		cout << 0 << endl;
		return 0;
	}
	ll m = 2 * y / 3 - x / 3, n = 2 * x / 3 - y / 3;
	if(m < 0 || n < 0) {
		cout << 0 << endl;
		return 0;
	}

	cout << C(m + n, m, mod) << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cstring>
#include <cassert>
#include <utility>
#include <iomanip>
#include <chrono>
#include <random>
#include <bitset>

using namespace std;

#define sz(x) (int) x.size()
#define unique(x) x.erase(unique(x.begin(), x.end()), x.end())
#define all(a) a.begin(), a.end()
#define sqr(x) ((x) * (x)) 
#define y1 aksjdaskdjksjfksdjf
#define left kdnvldvoiwejifejg
#define right lkdsjflksdjfdjfk
#define prev asdasfsadjkjsdfjs
#define tm aklsjdasjdasjdkdjjf
#define lcm hddalkwjeidjjhasda
#define random_shuffle asdasdd

const int MAXN = 2 * 105000;

int n;
vector<int> g[MAXN];
vector<int> nums[5];
int cnt[5];
int cntC[5];
int color[MAXN];

void dfs(int v, int col, int p = -1) {
  cntC[col]++;
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    dfs(to, 1 - col, v);
  }
}

void color1(int v, int colZero, int col, int p = -1) {
  if (col == colZero) {
    color[v] = nums[0].back();
    nums[0].pop_back();
  } else {
    if (sz(nums[1])) {
      color[v] = nums[1].back();
      nums[1].pop_back();
    } else if (sz(nums[2])) {
      color[v] = nums[2].back();
      nums[2].pop_back();
    } else if (sz(nums[0])) {
      color[v] = nums[0].back();
      nums[0].pop_back();
    }
  }
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    color1(to, colZero, 1 - col, v);
  }
}

void color2(int v, int col, int p = -1) {
  if (col == 0) {
    if (sz(nums[1])) {
      color[v] = nums[1].back();
      nums[1].pop_back();
    } else if (sz(nums[0])) {
      color[v] = nums[0].back();
      nums[0].pop_back();
    }
  } else {
    if (sz(nums[2])) {
      color[v] = nums[2].back();
      nums[2].pop_back();
    } else if (sz(nums[0])) {
      color[v] = nums[0].back();
      nums[0].pop_back();
    }
  }
  for (int to : g[v]) {
    if (to == p) {
      continue;
    }
    color2(to, 1 - col, v);
  }
}

int main() { 

  scanf("%d", &n);
  for (int i = 0; i < n - 1; i++) {
    int from, to;
    scanf("%d %d", &from, &to);
    from--; to--;
    g[from].push_back(to);
    g[to].push_back(from);
  }

  for (int i = 1; i <= n; i++) {
    cnt[i % 3]++;
    nums[i % 3].push_back(i);
  }

  dfs(0, 0);

  if (cntC[0] <= cnt[0]) {
    color1(0, 0, 0);
  } else if (cntC[1] <= cnt[0]) {
    color1(0, 1, 0);
  } else {
    color2(0, 0);
  }

  for (int i = 0; i < n; i++) {
    assert(color[i] != 0);
    printf("%d ", color[i]);
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 19448
def main():
    k, x = map(int, open(0).read().split())

    min_black = max(-1000000, x - (k - 1))
    max_black = min(1000000, x + (k - 1))
    ans = range(min_black, max_black + 1)
    print(*ans)
    return()

if __name__ == '__main__':
    main()


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

int main(){
  int n;
  cin >> n;
  map<string,int> mp;
  bool ok = true;
  string prev = "";
  rep(i,n){
    string s;
    cin >> s;
    if (i > 0) {
      if (prev.back() != s.front()) ok = false;
    }
    mp[s]++;
    if (mp[s] > 1) ok = false;
    prev = s;
  }
  if (ok) puts("Yes");
  else puts("No");
  return 0;
} 

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

struct restaurant {
    string city;
    int point;
    int index;
};

struct restaurant make_rest (string city, int point, int index) {
    struct restaurant tmp = {city, point, index};
    return tmp;
}

bool cmp_city(const restaurant &a, const restaurant &b) {
    return a.city < b.city;
}

bool cmp_point(const restaurant &a, const restaurant &b) {
    if (a.city < b.city) {
        return true;
    } else if (a.city == b.city) {
        return a.point > b.point;
    } else {
        return false;
    }
}

int main() {
    int n;
    string city;
    int point;
    vector<restaurant> rest_list;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> city >> point;
        rest_list.push_back(make_rest(city, point, i+1));
    }
    sort(rest_list.begin(), rest_list.end(), cmp_city);
    sort(rest_list.begin(), rest_list.end(), cmp_point);

    for (int i = 0; i < n; i++) {
        cout << rest_list[i].index << endl;
    }

    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
    public void solve(BufferedReader stdin, PrintWriter stdout) throws NumberFormatException, IOException {
        int n = Integer.parseInt(stdin.readLine());
        for (long a = 1; a <= 3500; a++) {
            for (long b = a; b <= 3500; b++) {
                long x = 4*a*b - a*n - b*n;
                long y = n*a*b;
                if (x > 0 && y > 0 && y % x == 0) {
                    long c = y / x;
                    stdout.printf("%d %d %d%n", a, b, c);
                    return ;
                }
            }
        }
    }

    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter stdout = new PrintWriter(System.out, false);
        new Main().solve(stdin, stdout);
        stdout.flush();
    }
}


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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    char n[3];

    Scs(n);

    Rep(i,3){
        if(n[i] == '1') {
            n[i] = '9';
        }else if(n[i] == '9'){
            n[i] = '1';
        }
    }

    printf ("%s\n", n);

    return 0;
}



Measured memory_bytes: 768
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdbool.h>

int main(void){
    int i,j;
    int N;
    double answer;
   
    scanf("%d",&N);
    
    if(N % 2 == 0){
        answer = (double)(N/2) / N;
    }else{
        answer = (double)(N/2 + 1) / N;
    }
    
    printf("%lf\n",answer);
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
// #define ll long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define eb emplace_back
#define pii pair<int, int>
#define endl '\n'
#define all(x) x.begin(),x.end()
#define f(i,j,l) for(i=j;i<l;i++)
#define smax(a,b) a=max(a,b)
// #if !defined(ONLINE_JUDGE)
// #include "debugging.h"
// #endif
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
// erase,insert same as normal set

// int const mod = 7340033;
int const mod = 998244353;
int power(int a,int b,int m){
    int res = 1;
    while(b){
        if(b&1){
            res = res*a;
            res %= m;
        }
        a=a*a;
        a%=m;
        b=b/2;
    }
    return res;
}

int inverse(int x , int m){
    return power(x,m-2,m);
}

int const N = 2e5+5;
int const inf = 2e16;

void solve(){  
    int i,j,l;
    string s,t;
    cin>>s>>t;
    int n = s.size();
    int ans = 0;
    for(i=0;i<n;i++){
        if(s[i]!=t[i]) ans++;
    }
    cout<<ans<<endl;
}           


int32_t main(){
    IOS;
    int t;
    t = 1;
    // precompute();
    // cin>>t;
    for(int tt=1;tt<=t;tt++){
        solve();
    }
    return 0;
}


/*

1 3 4 7 8 8 


*/

Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
typedef long long ll;


int main(void){
  int n,q,i,v,w;
  
  cin >> n >> q;
  
  if (n==1){
    for (i=0;i<q;i++){
      cin >> v >> w;
      cout << v << endl;
    }
    return 0;
  }
  
  for (i=0;i<q;i++){
    cin >> v >> w;
    set<int> s;
    while (v>0){
      s.insert(v);
      v=(v+n-2)/n;
    }
    while (1){
      if (s.find(w)!=s.end()) break;
      w=(w+n-2)/n;
    }
    cout << w << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1280
# -*- coding: utf-8 -*-
N, C, K = map(int, input().split())
T = []
for i in range(N):
    t1 = int(input())
    T.append(t1)
    
T.sort()
conut = 0
l = T[0]
n = 1
i = 0
ans = 0
while True:
    if T[i] - l > K:
        ans += 1
        n = 1
        l = T[i]
    elif n == C:
        if i <= N-2:
            l = T[i+1]
        ans += 1
        n = 0
    if i == N-1:
        if n > 0:
            ans += 1
        break
    i += 1
    n += 1    

print(ans)

Measured memory_bytes: 7384
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define MOD 1000000007
using namespace std;
map<pair<string,string>,ll> mp1,mp2;
void dfs(int k,string s,string r,string b,int l){
    if(k==s.size()){
        if(l==0){
            mp1[make_pair(r,b)]++;
        }
        else{
            mp2[make_pair(r,b)]++;
        }
        return;
    }
    dfs(k+1,s,r+s[k],b,l);
    dfs(k+1,s,r,b+s[k],l);

}
int main()
{
    int n;cin>>n;
    string s;cin>>s;
    string vo,s1,s2;
    s1=s.substr(0,n);
    s2=s.substr(n,n);
    reverse(all(s2));
    dfs(0,s1,vo,vo,0);
    dfs(0,s2,vo,vo,1);
    ll ans=0;
    for(auto p:mp1){
        ans+=p.second*mp2[p.first];
    }
    cout<<ans<<endl;
}

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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(ll i=0;i<(n);i++)


using namespace std;


int main(){
    ll n;
    cin >> n;
    vector<ll> t(n+1, 0);
    vector<ll> x(n+1, 0);
    vector<ll> y(n+1, 0);
    rep(i, n){
        cin >> t[i+1] >> x[i+1] >> y[i+1];
    }

    string o = "Yes";
    rep(i, n){
        ll dist = abs(x[i+1]-x[i]) + abs(y[i+1]-y[i]);

        ll r = ((t[i+1]-t[i])-dist);
        if(0 <= r && r%2 == 0){}
        else{
            o = "No";
            break;
        }
    }

    cout << o << endl;

    return 0;
}


Measured memory_bytes: 2560
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<functional>
#include<queue>
#include<math.h>
#define INF 999999

using namespace std;

typedef pair<int,int> P;
typedef pair<int, pair<int, int> > P2;
int r[100050];

void init(int n)
{
	for (int i = 0; i < n; i++) {
		r[i] = i;
	}
}

int find(int x)
{
	if (r[x] == x)return x;
	else {
		r[x] = find(r[x]);
		return r[x];
	}
}

void unite(int x, int y)
{
	x = find(x);
	y = find(y);
	r[x] = y;
}

int main()
{
	int n;
	cin >> n;
	vector<P> x;
	vector<P> y;
	
	for (int i = 0; i < n; i++) {
		int xi, yi;
		cin >> xi >> yi;
		x.push_back(P(xi,i));
		y.push_back(P(yi,i));
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	vector<P2> road;
	for (int i = 1; i < n; i++) {
		road.push_back(P2(x[i].first - x[i - 1].first, make_pair(x[i - 1].second,x[i].second)));
		road.push_back(P2(y[i].first - y[i - 1].first, make_pair(y[i - 1].second, y[i].second)));
	}
	sort(road.begin(), road.end());

	init(n);

	int cost = 0;
	int edge = 0;
	int i = 0;
	while(edge<=n-1&&i<road.size()){
		if (find(road[i].second.first) == find(road[i].second.second)) {
			i++;
			continue;
		}
		cost += road[i].first;
		unite(road[i].second.first, road[i].second.second);
		edge++;
		i++;
	}

	cout << cost << endl;

	return 0;
}



Measured memory_bytes: 7144
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
  int N,L;
  cin >> N >> L;
  vector<string>S(N);
  rep(i,N){
    cin >> S[i];
  }
  sort(S.begin(),S.end());
  string T;
  rep(i,N){
    T+=S[i];
  }
  cout << T << endl;
}

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

bool Compare(int a, int b) {
  a %= 10, b %= 10;
  if (a == 0) a = 10;
  if (b == 0) b = 10;
  return a > b;
}

int main() {
  int t[5];
  cin >> t[0] >> t[1] >> t[2] >> t[3] >> t[4];
  sort(t, t + 5, Compare);
  int ans = 0;
  for (int i = 0; i < 5; i++) {
    if (ans % 10 != 0) ans += 10 - ans % 10;
    ans += t[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
 
using namespace std;
const double PI=3.14159265358979323846;
 
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (n); ++i)

int main() {

	double x;
	cin >> x;

	int cut = 0;
	double sum = 100;
	while(sum < x) {
		long a = sum * 0.01;
		sum += a;
		cut++;
	}

	cout << cut << endl;
}



Measured memory_bytes: 3724
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = Integer.parseInt(in.nextLine());
		boolean result = false;
		for (int i = 0; i <= 100; i = i + 7) {
			for (int j = 0; i + j <= 100; j = j + 4) {
				if (i + j == n) {
					result = true;
					break;
				}
			}
			if (result) {
				break;
			}
		}
		if (result) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		in.close();
	}
}

Measured memory_bytes: 21972
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")

#include <cstdio>
#include <vector>
#include <algorithm>
#include <cassert>

using namespace std;

template <typename T>
class CumulativeSum2D {
 public:
  CumulativeSum2D(const std::vector<vector<T>>& vec)
      : vec_(vec), height_(vec.size()), width_(vec[0].size()) {
    Build();
  }
  // return sum of [sx, gx] * [sy, gy]
  T Get(int sx, int sy, int gx, int gy) {
    assert(sx <= gx && sy <= gy);
    assert(0 <= sx && sx < height_ && 0 <= gx && gx < height_ && 0 <= sy &&
          sy < width_ && 0 <= gy && gy < width_);
    return sum_[gx + 1][gy + 1] - sum_[gx + 1][sy] - sum_[sx][gy + 1] +
          sum_[sx][sy];
  }

 private:
  size_t height_;
  size_t width_;
  std::vector<vector<T>> vec_;
  std::vector<vector<T>> sum_;
  void Build() {
    sum_.assign(height_ + 1, vector<T>(width_ + 1, static_cast<T>(0)));
    for (size_t i = 0; i < height_; ++i) {
      for (size_t j = 0; j < width_; ++j) {
        sum_[i + 1][j + 1] = sum_[i + 1][j] + vec_[i][j];
      }
    }
    for (size_t i = 0; i < width_; ++i) {
      for (size_t j = 0; j < height_; ++j) {
        sum_[j + 1][i + 1] += sum_[j][i + 1];
      }
    }
  }
};

void ABC106_D() {
  int n, m, query; scanf("%d %d %d", &n, &m, &query);
  vector<vector<int>> board(n, vector<int>(n));
  for (int i = 0; i < m; ++i) {
    int l, r; scanf("%d %d", &l, &r); --l; --r;
    ++board[l][r];
  }

  CumulativeSum2D<int> cs2(board);

  for (int i = 0; i < query; ++i) {
    int p, q; scanf("%d %d", &p, &q);
    --p; --q;
    //cout << cs2.Get(p, p, q, q) << '\n';
    printf("%d\n", cs2.Get(p, p, q, q));
  }  
}

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

  ABC106_D();

  return 0;
}


Measured memory_bytes: 3840
#include <cstdio>
 
using namespace std;
 
int main(void){
  
  int x[5];
  
  scanf("%i%i%i%i%i", &x[0], &x[1], &x[2], &x[3], &x[4]);
  
  int i;
  for(i=0;i<5;i++){
    if(x[i]==0){
      printf("%i\n",(i+1));
    }
  }
    return 0;
}

Measured memory_bytes: 3244
#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 repi(i,a,b) for(int i=a; i<=(b); ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define mp make_pair
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using ll = long long;
using namespace std;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int n,tmp;
set<int> ma,mb;
map<int,int> a,b;

int freq(map<int,int> m,int n){
    int f = 0, mn = 0;
    for(auto itr = m.begin(); itr != m.end(); ++itr){
        if(itr->second >= mn && itr->first != n){
            mn = itr->second;
            f = itr->first;
        }
    }
    return f;
}

int main(){
    cin >> n;
    rep(i,n){
        cin >> tmp;
        if(i % 2) a[tmp]++;
        else b[tmp]++;
    }
    
    int a1 = freq(a,0);
    int a2 = freq(a,a1);
    int b1 = freq(b,0);
    int b2 = freq(b,b1);
    
    if(a1 != b1) cout << n - (a[a1] + b[b1]) << endl;
    else cout << n - max(a[a1]+b[b2],a[a2]+b[b1])<<endl;
}

Measured memory_bytes: 7296
void main()
{
    long n = rdElem;
    long[] a = n.rdCol;

    a.sort!"a > b";
    long h = n >> 1;

    long calc(long[] a)
    {
        long x, y;
        foreach (i; 0 .. h)
        {
            x += 2 * a[h-i-1];
            y += 2 * a[h+i+(n&1)];
        }
        if (n & 1) y += a[h] - a[h+1];
        else x -= a[h-1], y -= a[h];

        return abs(x-y);
    }

    long result = calc(a);
    reverse(a);
    result = max(result, calc(a));

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;
enum double eps = 1.0e-9;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.mathspecial;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;
import core.bitop;

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

typedef long long ll;
#define endl "\n"

const int M = (int) 1e9+7;
int n,k;
ll ans=1;
vector<ll> pos, neg;
int pcnt=0, ncnt=0;

ll solve(){
    cin>>n>>k;
    for (int i=0; i<n; ++i){
        ll foo; cin>>foo;
        if (foo>0) pos.push_back(foo);
        else neg.push_back(abs(foo));
    }
    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());
    int P=pos.size(), N=neg.size();
    if (k==n ? N%2==0 : P || k%2==0){
        reverse(pos.begin(), pos.end());
        reverse(neg.begin(), neg.end());
        for ( ; k; --k){
            if (pcnt<P && (ncnt>=N || pos[pcnt]>neg[ncnt])){
                ans=ans*pos[pcnt]%M; ++pcnt;
            }
            else{
                ans=ans*neg[ncnt]%M; ++ncnt;
            }
        }
        if (ncnt&1){
            ans=1;
            if (pcnt<P && ncnt>=1 && (ncnt>=N || pcnt<1 || pos[pcnt]*pos[pcnt-1]>neg[ncnt]*neg[ncnt-1])){
                for (int tt=0; tt<pcnt+1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt-1; ++tt)
                    ans=ans*neg[tt]%M;
            }
            else{
                for (int tt=0; tt<pcnt-1; ++tt)
                    ans=ans*pos[tt]%M;
                for (int tt=0; tt<ncnt+1; ++tt)
                    ans=ans*neg[tt]%M;
            }
        }
        return ans%M;
    }
    for(; k; --k) {
        if(pcnt<P &&(ncnt>=N || pos[pcnt]<neg[ncnt])) {
            ans=ans*pos[pcnt]%M;
            ++pcnt;
        } else {
            ans=ans*neg[ncnt]%M;
            ++ncnt;
        }
    }
    return (M-ans)%M;
}

int main(){
    // INT VS LL
    // freopen("input.txt", "r", stdin);
    //    INT VS LL
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout<<solve();
    return 0;
}


Measured memory_bytes: 5632
// #pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);
#define fou(i,a,n) for(int i=a;i<n;i++)
#define fod(i,a,n) for(int i=n-1;i>=a;i--)
#define rep(n) fou(_,0,n)
#define tra(a,x) for(auto& a : x)
#define elif(c) else if(c)
#define VI vector<int>
#define VD vector<double>
#define VC vector<char>
#define VS vector<string>
#define VVI vector<VI>
#define VVD vector<VD>
#define VVC vector<VC>
#define VVS vector<VS>
#define emb emplace_back
#define pub push_back
#define pob pop_back
#define mp make_pair
#define fi first
#define se second
#define si(vec) ((int)(vec).size())
#define all(vec) vec.begin(),vec.end()
#define lla(vec) vec.rbegin(),vec.rend()
#define range(vec,x,y) vec.begin()+x,vec.begin()+y
#define sortup(vec) sort(all(vec))
#define sortdown(vec) sort(lla(vec))
#define eraseif(vec,condition_x) vec.erase(remove_if(all(vec),[](auto x){return condition_x;}),vec.end())
#define countif(vec,condition_x) count_if(all(vec),[](auto x){return condition_x;})
#define replaceif(vec,condition_x,n) replace_if(all(vec),[](auto x){return condition_x;},n)
#define optvalue(vec,condition_x,relation_x_opt) *min_element(all(vec),[](int x,int opt){return condition_x ? (opt==0)||!(relation_x_opt):false;})
#define erase_unique(vec) vec.erase(unique(all(vec)),vec.end())
#define calcvec(vec,calc_x) for_each(all(vec),[](int&x){x= calc_x;})
#define calc2vec(vec1,op,vec2) {rep(1){int s=min(si(vec1),si(vec2));fou(i,0,s)vec1[i]=vec1[i] op vec2[i];}}
template<class C>void mini(C &a,C b){a=min(a,b);}
template<class C>void maxi(C &a,C b){a=max(a,b);}
#define in(T,...) T __VA_ARGS__;_cin(__VA_ARGS__);
#define out(...) _cout(__VA_ARGS__);
void _cin(){}template<class Head,class...Tail>void _cin(Head&head,Tail&&...tail){cin>>head;_cin(forward<Tail>(tail)...);}
template<class Head>void _cout(Head head){cout<<head<<endl;}template<class Head,class...Tail>void _cout(Head head,Tail...tail){cout<<head<<" ";_cout(forward<Tail>(tail)...);}
template<class C>void outvec(vector<C> vec){int vecsize=si(vec);fou(i,0,vecsize-1)cout<<vec[i]<<" ";out(vec[vecsize-1]);}
template<class C> C gcd(C a,C b){if(a&&b)return gcd(min(a,b),max(a,b)%min(a,b));else return a;}
template<class C> C lcm(C a,C b){return a/gcd(a,b)*b;}




// #define int int64_t
// #define double long double


// 無名関数template
// map,makepair

signed main(){
  IOS;

  in(string,s1,s2,s3);
  string ans="000";

  ans[0]=s1[0]+'A'-'a';
  ans[1]=s2[0]+'A'-'a';
  ans[2]=s3[0]+'A'-'a';
  out(ans);

}

Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        s: String
    }
    let ans = s.chars().fold(String::from(""), |mut buff, c| if buff.ends_with(c) {
        buff
    } else {
        buff.push(c);
        return buff;
    }).len();
    println!("{}", ans);
}


Measured memory_bytes: 2432
#include <iostream>
#include <cmath>
#include <algorithm>
#include <set>

using namespace std;
using ll = long long;
using Set = multiset<ll>;

bool is_prime (ll n) {
  if (n == 1) return false;
  if (n == 2) return true;
  if (n == 3) return true;

  ll sqrtn = sqrt(n);

  for (ll i = 2; i < sqrtn + 1; i++) {
    if (n % i == 0) return false;
  }

  return true;
}

Set get_prime_factors (ll n) {
  ll sqrtn = sqrt(n);
  Set prime_factors;

  for (ll i = 1; i < sqrtn + 1; i++) {
    if (n % i != 0) continue;

    ll I = n / i;

    if (is_prime(i)) prime_factors.insert(i);
    if (is_prime(I)) prime_factors.insert(I);
  }

  return prime_factors;
}

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

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

  ll g = gcd(A, B);
  Set S = get_prime_factors(g);

  S.insert(1);

  cout << S.size() << endl;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
	int n,i,j,sum=0;
	scanf("%d",&n);
	int a[n];
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);	
	}
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			if(i!=j){
				sum+=a[i]*a[j];
			}
		}
	}
	printf("%d",sum/2);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define ll long long int
#define sci(x) sca nf("%d",&x);
#define scd(x) scanf("%lf",&x);
#define pb(x) push_back(x)
#define FasterIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mkp(x,y) make_pair(x,y)
#define pii pair<int , int>
#define SEIVE seive(){ prime[1]=1; for(ll i=2; i*i<=1000000; i++) { if(prime[i]) continue; for(ll j=i*i; j<=1000000; j+=i) prime[j]=1; } }
bool prime[1000006];
vector<int>vec[20000],root;
int vis[20002];

int main()
{
    int n,k;
    cin>>n>>k;
    int a[n+3];
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum<<endl;

}


Measured memory_bytes: 4108
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
#define rep(i,n) for(int i=0; i<(n); i++)
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 main(){
    ll mod=1000000007;
    ll n; cin>>n;
    //vector<ll> a(n);
    ll ans=1;
    vector<ll> hat(3,0);
    rep(i,n){
        ll a; cin>>a;
        ll cnt=0;
        rep(j,3){
            if(hat[j]==a)cnt++;
        }
        ans*=cnt;
        ans%=mod;
        rep(j,3){
            if(hat[j]==a){hat[j]++; break;}
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <stdio.h>

int main() {
  long long X;
  scanf("%lld", &X);

  for(long long a=-200; a<200; a++){
    for(long long b=-200; b<200; b++){
      if(a*a*a*a*a-b*b*b*b*b==X){
        printf("%lld %lld", a, b);
        return 0;
      }
    }
  }
}

Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
int dp[100100][4],ac[100100][3];
int n;
int ds(int id, int a) {
	if(id == n) {return 0;}
	if(dp[id][a] != -1) {return dp[id][a];}
	int val = 0;
	for(int i=0;i<3;i++) {
		if(a == i) {continue;}
		val = max(val,ac[id][i] + ds(id+1,i));
	}
	//printf("%d %d %d\n",val,id,a);
	return dp[id][a] = val;
}
int main() {
	scanf("%d ",&n);
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<n;i++) {
		for(int j=0;j<3;j++) {
			int t;
			scanf("%d ",&ac[i][j]);
		}
	}
	printf("%d\n",ds(0,3));
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;
ll N, Q;
string S;

ll solve(ll k) {
    ll ret = 0;
    ll D = 0;
    ll M = 0;
    ll C = 0;
    REP(i, N) {
        if (i - k >= 0) {
            ll index = i - k;
            if (S[index] == 'D') {
                D--;
                C -= M;
            }
            else if (S[index] == 'M') {
                M--;
            }
        }

        if (S[i] == 'C')
            ret += C;
        else if (S[i] == 'M') {
            M++;
            C += D;
        }
        else if (S[i] == 'D')
            D++;
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> S >> Q;
    REP(i, Q) {
        ll k;
        cin >> k;
        cout << solve(k) << endl;
    }
    return 0;
}

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

int comp(const void* a, const void* b) {
  return *(int*)a - *(int*)b;
}

int main(void) {
  FILE *fp;
  fp = stdin;
  char line[15];
  if(!fgets(line, 15, fp)) return 0;
  int num, constraint;
  int i;
  sscanf(line, "%d %d", &num, &constraint);

  int min = 100001;
  int sum = 0;
  int res = 0;
  for(i = 0; i < num; i++) {
    if(!fgets(line, 15, fp)) return 0;
    int q;
    sscanf(line, "%d", &q);
    if(q < min) min = q;
    sum += q;
  }
  res = num;
  while(sum+min <= constraint) {
    sum += min;
    res++;
  }

  printf("%d\n", res);
  return 0;
}

Measured memory_bytes: 128
def A():
    c = input()
    print(chr(ord(c)+1))

def B():
    temp = [int(k) for k in input().split()]
    N = temp[0]
    K = temp[1]
    M = temp[2]
    A = [int(k) for k in input().split()]
    ans = M*N - sum(A)
    if ans <= K:
        print(max(0, ans))
    else:
        print(-1)

from collections import defaultdict
def C():
    temp = [int(k) for k in input().split()]
    N = temp[0]
    M = temp[1]
    penal = defaultdict(int)
    P = []
    S = []
    for i in range(M):
        temp = input().split()
        P.append(int(temp[0]))
        S.append(temp[1])
    ac_problems = set()

    for i in range(M-1, -1, -1):
        if P[i] not in ac_problems and S[i] == 'AC':
            ac_problems.add(P[i])
        elif P[i] in ac_problems:
            if S[i] == 'WA':
                penal[P[i]] += 1
            elif S[i] == 'AC':
                penal[P[i]] = 0
    
    print(len(ac_problems), sum(penal.values()))
C()

Measured memory_bytes: 19908
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const int INF = (int) 1e9;

int val[100005], color[100005], answer[200005];
pair <int, int> mas[100005];
vector <pair <int, int> > g[100005];

int dfs(int v)
{                
 	int kol = 1;
 	for (int i = 0; i < (int) g[v].size(); i++)
 	{
 	 	int u = g[v][i].x, num = g[v][i].y;
 	 	if (val[u] == val[v] && color[u] == -1)
 	 	{
 	 	 	color[u] = color[v] ^ 1;
 	 	 	answer[num] = val[v];
 	 	 	kol += dfs(u);
 	 	}
 	}
 	return kol;
}

int main()
{
 	//freopen("input.txt", "r", stdin);
 	//freopen("output.txt", "w", stdout);
 	ios_base::sync_with_stdio(0); cin.tie(0);
 	int n, m;
 	cin >> n >> m;
 	for (int i = 1; i <= n; i++) cin >> val[i];
 	for (int i = 1; i <= m; i++)
 	{
 	 	int u, v;
 	 	cin >> u >> v;
 	 	g[u].pb(mp(v, i)), g[v].pb(mp(u, i));
 	}
 	for (int i = 1; i <= n; i++) color[i] = -1;
 	for (int i = 1; i <= m; i++) answer[i] = -1;

 	for (int i = 1; i <= n; i++) mas[i] = mp(val[i], i);
 	sort(mas + 1, mas + n + 1);
 	
 	int lef = 1, rig = 0;
 	while (lef <= n)
 	{
 	 	rig = lef;
 	 	while (rig < n && mas[rig + 1].x == mas[lef].x) rig++;
 	 	
 	 	vector <int> spis;
 	 	for (int i = lef; i <= rig; i++)
 	 	{
 	 	 	int v = mas[i].y;
 	 	 	bool fl1 = false, fl2 = false;
 	 	 	for (int j = 0; j < (int) g[v].size(); j++)
 	 	 	{
 	 	 	 	int u = g[v][j].x;
 	 	 	 	if (val[u] < val[v]) fl1 = true;
 	 	 	 	if (val[u] == val[v]) fl2 = true;
 	 	 	}
 	 	 	if (!fl1 && !fl2) cout << "-1\n", exit(0);

 	 	 	if (fl1)
 	 	 	{
 	 	 	 	for (int j = 0; j < (int) g[v].size(); j++)
 	 	 	 	{
 	 	 	 	 	int u = g[v][j].x, num = g[v][j].y;
 	 	 	 	 	if (val[u] < val[v])
 	 	 	 	 	{
 	 	 	 	 	 	color[v] = color[u];
 	 	 	 	 	 	answer[num] = val[v] - val[u];
 	 	 	 	 	 	break;
 	 	 	 	 	}
 	 	 	 	}
 	 	 	}
 	 	 	else spis.pb(v);
 	 	}

 	 	for (int i = 0; i < (int) spis.size(); i++)
 	 	{
 	 	 	if (color[spis[i]] == -1)
 	 	 	{
 	 	 	 	color[spis[i]] = 0;
 	 	 	 	int sch = dfs(spis[i]);
 	 	 	 	if (sch == 1)
 	 	 	 	{
 	 	 	 		for (int j = 0; j < (int) g[spis[i]].size(); j++)
 	 	 	 		{
 	 	 	 		 	int u = g[spis[i]][j].x, num = g[spis[i]][j].y;
 	 	 	 		 	if (val[u] == val[spis[i]] && color[u] != -1)
 	 	 	 		 	{
 	 	 	 		 	 	color[spis[i]] = color[u] ^ 1;
 	 	 	 		 	 	answer[num] = val[u];
 	 	 	 		 	 	break;
 	 	 	 		 	}
 	 	 	 		}
 	 	 	 	}
 	 	 	}
 	 	}

 	 	lef = rig + 1;
 	}
 	string s = "";
 	for (int i = 1; i <= n; i++) if (color[i] == 0) s += 'W'; else s += 'B';
 	cout << s << '\n';
 	for (int i = 1; i <= m; i++)
 	{
 	 	if (answer[i] == -1) answer[i] = INF;
 	 	cout << answer[i] << '\n';
 	}
 	return 0;
}

Measured memory_bytes: 13672
#include <bits/stdc++.h>
#define int long long
#define db long double
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(a) a.begin(), a.end()

using namespace std;



main(){
#ifdef LOCAL
	freopen("A_input.txt", "r", stdin);
	//freopen("A_output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int k;
	cin >> k;
	bool diff = false;
	for (int i=1; i < s.size(); ++i){
		if (s[i] != s[i-1]) diff = true;
	}

	if (!diff){
		cout << s.size()*k/2;
		return 0;
	}
	int ans=0;
	for (int i=1; i < s.size(); ++i){
		if (s[i-1] == s[i]) continue;
		int steps = 0;
		for (int j=0; j < s.size(); ++j){
			if (s[(i+j)%s.size()] == s[i]) steps++;
			else break;
		}
		ans += (steps/2)*(k-1);
		steps=0;
		for (int j=0; j < s.size();++j){
			int tr = j+i;
			if (tr >= s.size()) break;
			if (s[tr] == s[i]) steps++;
			else break;
		}
		ans += steps/2;
	}
	int f = 1;
	for (int i=1; i < s.size(); ++i){
		if (s[i] == s[0]) f++;
		else break;
	}
	if (s[0] == s.back()){
		ans += f/2;
	}
	else ans += (f/2)*k;
	cout << ans;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
using namespace std;

    int main() {
        int r,D,x,m;
        cin>>r>>D>>x;
        for (int i = 0; i <10 ; ++i) {
            m=(r*x-D);
            x=m;
            cout<<m<<endl;
        }
    }


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

int main() {
  int N, A, B;
  cin >> N;
  B = 30;
  for(int i = 0; i < N; i++) {
    int total = 0;
    cin >> A;
    while(A % 2 == 0) {
      A = A / 2;
      total += 1;
    }
    if(B > total) {
       B = total;
    }
    else {
      continue;
    }
  } 
  cout << B << endl;
}

Measured memory_bytes: 3604
N = int(input()) 

S={}

for i in range(N):
    x = str(input())
    
    if x in S.keys():
        S[x] += 1
    else:
        S[x] = 1
        
if "AC" in S.keys():
    print("AC x " + str(S["AC"]))
else:
    print("AC x " +"0" )
    
if "WA" in S.keys():
    print("WA x " + str(S["WA"]))
else:
    print("WA x " +"0" )
    
if "TLE" in S.keys(): 
    print("TLE x " + str(S["TLE"]))
else:
    print("TLE x " +"0")
    
if "RE" in S.keys():
  print("RE x " + str(S["RE"]))
else:
  print("RE x " + "0" )

Measured memory_bytes: 9252
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
//#include<stdlib.h>
using namespace std;
int main() {
	int n, k;
	string s;
	cin >>n>>k>> s;k--;
	if (s[k] == 'A') { s[k] = 'a'; }
	else if (s[k] == 'B') { s[k] = 'b'; }
	else { s[k] = 'c'; }
	cout << s;
	return 0;
}

Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().rstrip()
from collections import Counter
def main():
    X=input()
    cunt=0
    cunt_s=0
    for x in X:
        if x=='S':
            cunt_s+=1
        elif cunt_s>0:
            cunt_s-=1
        else:
            cunt+=1
    print(cunt+cunt_s)

if __name__=='__main__':
    main()

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

#define int long long
#define vec vector
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define sq(x) (x)*(x)
#define fast_io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

using namespace std;
typedef pair<long long, long long> PII;
typedef long double ld;
struct ver{
    bool mas[26];
};
void nul(ver &a){
    for(auto &i: a.mas) i = false;
}
vec < ver > tree;
vec < int > q;
ver un(ver a, ver b){
    ver c;
    for(int i = 0; i < 26; ++i)
        c.mas[i] = (a.mas[i]|b.mas[i]);
    return c;
}
void build(int v, int tl, int tr){
    nul(tree[v]);
    if(tl == tr){
        tree[v].mas[q[tl]] = true;
        return;
    }
    int t = (tl+tr)/2;
    build(2*v, tl, t);
    build(2*v+1, t+1, tr);
    tree[v] = un(tree[2*v], tree[2*v+1]);
}
void up(int v, int tl, int tr, int x, int ch){
    if(tl == tr){
        tree[v].mas[q[tl]] = false;
        tree[v].mas[ch] = true;
        q[tl] = ch;
        return;
    }
    int t = (tl+tr)/2;
    if(x <= t) up(2*v, tl, t, x, ch);
    else up(2*v+1, t+1, tr, x, ch);
    tree[v] = un(tree[2*v], tree[2*v+1]);
}
ver get(int v, int tl, int tr, int l, int r){
    if(l <= tl && tr <= r) return tree[v];
    int t = (tl+tr)/2;
    ver one;
    ver two;
    nul(one);
    nul(two);
    if((l <= tl && tl <= r) || (l <= t && t <= r) || (tl <= l && r <= t))
        one = get(2*v, tl, t, l, r);
    if((l <= t+1 && t+1 <= r) || (l <= tr & tr <= r) || (t+1 <= l && r <= tr))
        two = get(2*v+1, t+1, tr, l, r);
    return un(one, two);
}
signed main()
{
    fast_io;
    int n;
    string s;
    cin >> n >> s;
    q.resize(n);
    tree.resize(4*n);
    for(int i = 0; i < n; ++i){
        q[i] = s[i]-'a';
    }
    build(1, 0, n-1);
    int t;
    cin >> t;
    int l, r;
    char a;
    while(t--){
        int type;
        cin >> type;
        if(type == 1){
            cin >> l >> a;
            r = a-'a';
            l--;
            up(1, 0, n-1, l, r);
        }else{
            cin >> l >> r;
            l--, r--;
            ver ans = get(1, 0, n-1, l, r);
            int otv = 0;
            for(int j = 0; j < 26; ++j)
                if(ans.mas[j]) otv++;
            cout << otv << "\n";
        }
    }
    return 0;
}


Measured memory_bytes: 55580
#include <iostream>
#include <algorithm>
#define rep(i, a, n) for(int i = a;i < n;i++)
#define repr(i, a, n) for(int i = a;i > n;i--)
using namespace std;


const int INF = 999999999;
int h, w;
char s[55][55];
int g[2510][2510];
int d[2510];
bool used[2510];


void makeGW(int i, int j){
	if(j == w - 1) return;
	if(s[i][j+1] == '#') return;
	g[i*w + j][i*w + j + 1] = 1;
	g[i*w + j + 1][i*w + j] = 1;
}


void makeGH(int i, int j){
	if(i == h - 1) return;
	if(s[i+1][j] == '#') return;
	g[i*w + j][i*w + j + w] = 1;
	g[i*w + j + w][i*w + j] = 1;
}


void makeG(){
	rep(i, 0, h*w) d[i] = INF, used[i] = false;
	d[0] = 0;
	rep(i, 0, h){
		rep(j, 0, w){
			makeGW(i, j);
			makeGH(i, j);
		}
	}
}


void dijkstra(){
	while(true){
		int v = -1;
		
		rep(u, 0, h*w){
			if(!used[u] && (v == -1 || d[u] < d[v])) v = u;
		}

		if(v == -1) break;

		used[v] = true;

		rep(u, 0, h*w)
			d[u] = min(d[u], d[v] + (g[v][u] ? g[v][u] : INF));
	}
}


int cntB(){
	int ret = 0;
	rep(i, 0, h)
		rep(j, 0, w)
			if(s[i][j] == '#') ret++;
	return ret;
}


int main(){
	cin >> h >> w;
	rep(i, 0, h)
		rep(j, 0, w) cin >> s[i][j];

	makeG();

	dijkstra();

	int b = cntB();

	if(d[h*w - 1] == INF){ cout << -1 << endl; return 0; }
	cout << h*w - b - (d[h*w - 1] - 1) - 2 << endl;

	return 0;
}

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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 100005
#define ALL(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)


using namespace std;
vector<vector<int>> v;
vector<int> ok;
map<int,int> mp;
vector<int> len;
int n;
void bfs(int s)
{
	queue<int> que;
	que.push(s);
	ok[s] = 1;
	while(!que.empty())
	{
		int p = que.front();
		que.pop();
		//cout<<p<< " ";
		for(auto x : v[p])
		{
			if(!ok[x])
			{
				///cout<<x<<" ";
				que.push(x);
				ok[x] = 1;
				len[x] = len[p] + 1;
			}
		}	
	}
	for (int i = 0; i < n; i++)
	{
		mp[len[i]]++;
	}
}

int32_t main()
{
    IOS;

    int tt=1;
    //cin>>tt;
    while(tt--)
    {
         cin>>n;
         //n++;
        v.resize(n);
        ok.resize(n,0);
        len.resize(n,0);
        
		for (int i = 0; i < n - 1; i++)
		{
			v[i].EB(i+1);
			v[i+1].EB(i);
		}
		//exit(0);
		int a,b; cin>>a>>b;
		v[a-1].EB(b-1);
		v[b-1].EB(a-1);
		
		for (int i = 0; i < n; i++)
		{
			fill(ALL(len),0);
			fill(ALL(ok),0);
			bfs(i);
		}
		
		for (int i = 1; i < n; i++)
		{
			if(mp.count(i) == 0) mp[i] = 0;
			cout<<mp[i]/2<<endl;
		}
		
	
		
		cout<<endl;
    }
    return 0;

}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n;i++)
#define ll long long
#include <bits/stdc++.h>
using namespace std;
#define mo 1000000007
#define ull unsigned long long 

int main(){
  ull n;cin>>n;
  ull a,b;cin>>a>>b;
  ull sum=n/(a+b);
  ull cnt=n%(a+b);
  if(cnt>=a)
    cout<<sum*a+a;
  else
    cout<<sum*a+cnt;
}
  
    
  

Measured memory_bytes: 256
import numpy as np
def convolve(A, B):
    # 畳み込み  # 要素は整数
    # 3 つ以上の場合は一度にやった方がいい
    dtype = np.int64
    fft, ifft = np.fft.rfft, np.fft.irfft
    a, b = len(A), len(B)
    if a == b == 1:
        return np.array([A[0]*B[0]])
    n = a+b-1  # 返り値のリストの長さ
    k = 1 << (n-1).bit_length()
    AB = np.zeros((2, k), dtype=dtype)
    AB[0, :a] = A
    AB[1, :b] = B
    return np.rint(ifft(fft(AB[0]) * fft(AB[1]))).astype(np.int64)[:n]

import sys
input = sys.stdin.readline
n,m = map(int, input().split())
a = list(map(int, input().split()))
 
cnt = np.zeros(100001)
for i in a:
    cnt[i] += 1 

c = convolve(cnt,cnt)
ans = 0
for i in range(len(c))[::-1]:
    if c[i] > 0:
      p = min(m,c[i])
      m -= p
      ans += i*p
      if m == 0:
        break
print(ans)

Measured memory_bytes: 44616
#include<stdio.h>
#include <stdlib.h>
#include<math.h>
int main(){
    float n,m,count=0;
    //scanf("%f %f "&sum,&m);
    //sum=117;m=3;
    int arr[10000],sum=0;
    scanf("%f %f",&n,&m);
    for(int i=0;i<=n-1;i++){
        scanf("%i",&arr[i]);sum+=arr[i];
    }
    float k=(sum/(4*m));
    int k1=ceil(k);
    //printf("%0.0f\n",k);
    for(int i=0;i<=n-1;i++){
         if(arr[i]>=k1){
             count++;
         }
    }
    
    if(count>=m){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    return 0;
}

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


int main(){

  int X;
  int A,B,C,D;
  int op[3]={0};
  string ops[3]={};
  int tmp=0;

  cin >> X;

  D = X % 10;
  C = ((X-D) / 10) % 10;
  B = ((X - 10 * C - D) / 100) % 10;
  A = ((X - 100 * B - 10 * C - D) / 1000) % 10;

  for(int i=0;i<8;i++){
    tmp=i;
    for(int j=0;j<3;j++){
      op[j] = 1 - 2 * (tmp % 2);
      tmp = (tmp - (tmp % 2)) / 2;
    }
    if(A + op[0]* B + op[1] * C + op[2] * D == 7)
      break;
  }
  
  for(int i=0;i < 3; i++)
    if(op[i]==1) ops[i]="+";
    else        ops[i]="-";

  cout << A << ops[0] << B << ops[1] << C << ops[2] << D << "=7" << endl;

  return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;

short dp[4001][4001];

int main(){
	string str1;
	while(cin>> str1){
		memset(dp,0,sizeof(dp));

		string str2;
		cin >> str2;

		for(int i=0;i<str1.size();i++){
			for(int j=0;j<str2.size();j++){
				if(str1[i] == str2[j]){
					dp[i+1][j+1] = dp[i][j]+1;
				}
				else{
					dp[i+1][j+1] = 0;
				}
			}
		}

		short res=0;
		for(int i=0;i<=str1.size();i++){
			for(int j=0;j<=str2.size();j++){
				res = max(res,dp[i][j]);
			}
		}

		printf("%d\n",res);
	}
}

Measured memory_bytes: 31000
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
/*
箱すくな
鍵の有無で2^1000は無理
箱ごとに鍵をいれて、最安値を順番に。12!通り？
なんかだめそう

bit探索とDP組み合わせ、すご。
2^12=4096
鍵1本につき毎回4096回DPしてる
|= いみわかった

自分が1001
1=min(1,自分)
10=min(10)
あくまで自分との論理和だけ更新で、4096通りは全部ながす
いや、でも0001を更新するには？
論理積も更新
1001&0001=0001
*/
int main(){
  ll N,M,oo=4e9; cin>>N>>M;
  vector<ll> A(M+1,0), B(M+1,0), DP(5000,oo);
  DP[0]=0;
  for(ll i=1; i<=M; i++){
    ll a,b; cin>>a>>b;
    A[i]=a;
    ll n=0;
    for(ll j=0; j<b; j++){
      ll c; cin>>c;
      n|=(1<<(c-1));
    }
    B[i]=n;//1 2 4 = 11が入る
  }
  
  for(ll i=1; i<=M; i++){//鍵
    for(ll j=1; j<(1<<N); j++){//bit
      ll x=B[i]&j;
      ll y=B[i]|j;
      DP[x]=min(DP[x], A[i]);
      DP[y]=min(DP[y], DP[j]+A[i]);
    }
  }
  ll ans=DP[(1<<N)-1];
  if(ans==oo) ans=-1;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;

ll h, w, n;
vector<pair<ll, ll>> c;

int in(ll a, ll b) {
    if (a < 0 || a >= h || b < 0 || b >= w) return -1;
    
    ll l = 0, r = n;
    while (r - l > 1) {
        ll mid = (l + r) / 2;
        //cout << c[mid].first * 1000000000 + c[mid].second << endl;
        
        if (c[mid].first * 1000000000 + c[mid].second <= a * 1000000000 + b) l = mid;
        else r = mid;
    }
    if (c[l].first * 1000000000 + c[l].second == a * 1000000000 + b) return 1;
    else return 0;
}

int main(void){
    cin >> h >> w >> n;
    for (int i = 0; i < n; i++) {
        ll a, b;
        cin >> a >> b;
        a--;  b--;
        c.emplace_back(a, b);
    }
    sort(c.begin(), c.end());
    
    ll ans[10] = {};
    for (int i = 0; i < n; i++) {
        for (int p = 0; p < 9; p++) {
            int bl = 0;
            for (int q = 0; q < 9; q++) {
                if (in(c[i].first - 2 + p / 3 + q / 3, c[i].second - 2 + p % 3 + q % 3) == 1) bl++;
                else if (in(c[i].first - 2 + p / 3 + q / 3, c[i].second - 2 + p % 3 + q % 3) == -1) {
                    bl = -1;  break;
                }
            }
            //cout << i << " (" << c[i].first << ", " <<c[i].second  << ") " << p/3 << " " << p%3 <<" " <<bl << endl;
            if (bl != -1) ans[bl]++;
        }
    }
    
    
    //for (int i = 1; i < 10; i++) cout << ans[i] << endl;
    
    ll sum = 0;
    for (int i = 1; i < 10; i++) {
        ans[i] /= i;
        sum += ans[i];
    }
    
    cout << (h - 2) * (w - 2) - sum << endl;
    for (int i = 1; i < 10; i++) cout << ans[i] << endl;
    
    
    
}


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

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int w, a, b; cin >> w >> a >> b;
	if(b+w < a) cout << a-b-w << '\n';
	else if(a+w < b) cout << b-a-w << '\n';
	else cout << 0 << '\n';
	return 0;
}

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

int main() {
  int num;
  int dice1, dice2;
  cin >> num;
  int count = 0;
  int y = 0;
  for (int i=0; i<num; i++){
  	cin >> dice1 >> dice2;
    if(dice1 == dice2){
     count++;
    } else if (dice1 != dice2){
     count = 0;
    }
    if(count==3){
      cout << "Yes" << endl;
      y++;
      break;
    }
  }
  if(y == 0){
  	cout << "No" <<endl;
  }
}

Measured memory_bytes: 3600