akhauriyash/Code-Regression huggingface dataset:
#include <iostream> // cout, endl, cin
#include <iomanip>
#include <string>        // string, to_string, stoi
#include <vector>        // vector
#include <algorithm>     // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility>       // pair, make_pair
#include <tuple>         // tuple, make_tuple
#include <cstdint>       // int64_t, int*_t
#include <cstdio>        // printf
#include <map>           // map
#include <queue>         // queue, priority_queue
#include <set>           // set
#include <stack>         // stack
#include <deque>         // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset>        // bitset
#include <cctype>        // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <numeric>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
const int INF = 1001001001;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> x(M);
    vector<int> v(M - 1);
    rep(i, M) cin >> x.at(i);
    sort(x.begin(), x.end());
    rep(i, M - 1)
    {
        v.at(i) = x.at(i + 1) - x.at(i);
    }
    sort(v.begin(), v.end());

    int ans = 0;
    rep(i, (M - 1) - (N - 1))
    {
        ans += v.at(i);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    long long int n,m;
    cin >> n >> m;

    long long int a[m];
    for(int i=0;i<m;i++)cin >> a[i];

    for(int i=0;i<m;i++)n -= a[i];


    if(n>=0)cout << n << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 3700
fn main() {
    let n = read::<usize>();
    let a_list = read_vec::<usize>();
    let result = solve(n, a_list);
    let strings: Vec<String> = result.iter().map(|&i| i.to_string()).collect();
    println!("{}", strings.join(" "));
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn solve(n: usize, a_list: Vec<usize>) -> Vec<usize> {
    let mut result = vec![0; n];
    for (i, &val) in a_list.iter().enumerate() {
        result[val - 1] = i + 1;
    }
    result
}


Measured memory_bytes: 11004
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define loINF (long)10000000000
#define shINF (short)10000
#define SORT(c) sort((c).begin(),(c).end())
using namespace std;
typedef vector<long> VI;
typedef vector<VI> VVI;

VI lowest;
VI dfs_order;
VI ver_dfs_order;
VI prever;
VVI edge;

void dfs_tree(long ver,long dfs_ord,long pre){
	long nextver;
	prever[ver] = pre;
	dfs_order[ver] = dfs_ord ;
	ver_dfs_order[dfs_ord] = ver;
	lowest[ver] = dfs_ord ;

	REP(i,edge[ver].size()){
		long nextver_num = 1;
		long now_ver;
		nextver = dfs_order[edge[ver][i]];
		now_ver = ver;
		if (nextver < lowest[ver]) {
			while (nextver < lowest[now_ver]){
				lowest[now_ver] = nextver;
				now_ver = prever[now_ver];
			}
		}
		else {
			if (nextver == loINF) {
				dfs_tree(edge[ver][i],dfs_ord+nextver_num,ver);
				nextver_num++;
			}
		}
	}
}
int main(void){
	long V,E;
	long ans = 0;
	short root_count = 0;
	cin >> V >> E;
	lowest = VI(V+1,0);
	dfs_order = VI(V+1,loINF);
	ver_dfs_order = VI(V+1,0);
	prever = VI(V+1,loINF);
	edge = VVI(V+1,VI(0));

	REP(i,E){
		long ver1,ver2;
		cin >> ver1 >> ver2;
		edge[ver1].push_back(ver2);
		edge[ver2].push_back(ver1);
	}

	dfs_tree(V-1,1,loINF);

	ver_dfs_order = VI(0);
	REP(i,V-1){
		long  parent = prever[i];
		if (parent == loINF) continue;
		if (parent == V-1) root_count++;
		else { if (dfs_order[parent] <= lowest[i]) ver_dfs_order.push_back(parent); }
	}

	#ifdef DEBUG
		dump1d_arr(lowest);
		dump1d_arr(dfs_order);
		dump1d_arr(prever);
	#endif
	SORT(ver_dfs_order);
	ver_dfs_order.erase(unique(ver_dfs_order.begin(),ver_dfs_order.end()),ver_dfs_order.end());
	REP(i,ver_dfs_order.size()) cout << ver_dfs_order[i] << endl;
	if (root_count >= 2) cout << (V-1) << endl;

	return 0;
}




Measured memory_bytes: 5056
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vector<ll> > vvl;
typedef vector<vector<P> > vvp;
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; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  
  int n,k;
  cin >> n >> k;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  
  ll ans=INF;
  rep(i,n-k+1){
    chmin(ans,h[i+k-1]-h[i]);
  }
  cout << ans << endl;
    
  return 0;     
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
  int N;
  cin >> N;
  vector<vector<int>> a(2, vector<int>(100));
  for (int i=0; i<2; ++i) {
    for (int j=0; j<N; ++j) {
      cin >> a[i][j];
    }
  }
  int max=0;
  for (int i=0; i<N; i++) {
    int samp=0;
    for (int j=0; j<N; j++) {
      if (j < i) {
        samp += a[0][j];
      }
      else if (j == i) {
        samp += a[0][j];
        samp += a[1][j];
      }
      else {
        samp += a[1][j];
      }
    }
    if (max < samp) {
      max = samp;
    }
  }
  cout << max;
  return 0;
}



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

namespace es
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string T = Console.ReadLine();
            Console.WriteLine(Enumerable.Range(0, 3).Aggregate(0, (x, y) => x + (S[y] != T[y] ? 0 : 1)));
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<ld> vd;
typedef bool bl;
typedef vector<bl> vb;
typedef unordered_map<ll,unordered_map<ll,ll>> graph;

const ll e5 = 1 << 20;
const ll mod = 1000000007;
const ll e3 = 1 << 13;
const ll INF = 1ll << 60;

ll n,m;
graph g;
graph r;
ll s,t;
ll vis[e5];
ll level[e5];
ll idx;
ll ans = 0;
vl anss;

void bfs(){
  queue<vl> q;
  q.push(vl({s,0}));
  vis[s]++;
  while(!q.empty()){
    vl p = q.front();
    q.pop();
    ll x = p[0];
    ll l = p[1];
    level[x] = l;
    for(auto y : g[x]){
      if(vis[y.first] == 1) continue;
      if(y.second == 0) continue;
      vis[y.first]++;
      q.push(vl({y.first,l+1}));
    }
    for(auto y : r[x]){
      if(vis[y.first] == 1) continue;
      if(y.second == 0) continue;
      vis[y.first]++;
      q.push(vl({y.first,l+1}));
    }

  }
}

ll dfs(ll x,ll c){
  vis[x]++;
  if(x == t) return c;
  for(auto y : g[x]){
    if(vis[y.first] == 1) continue;
    if(y.second == 0) continue;
    if(level[y.first] <= level[x]) continue;
    ll z = dfs(y.first, min(c,y.second));
    if(z > 0){
      g[x][y.first] -= z;
      r[y.first][x] += z;
      return z;
    }
  }
  for(auto y : r[x]){
    if(vis[y.first] == 1) continue;
    if(y.second == 0) continue;
    if(level[y.first] <= level[x]) continue;
    ll z = dfs(y.first, min(c,y.second));
    if(z > 0){
      r[x][y.first] -= z;
      g[y.first][x] += z;
      return z;
    }
  }
  return 0;
}

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

int main(){
  while(true){
    cin >> n >> m;
    if(n == 0 && m == 0) break;
    vl b(n+1);
    vl c(m+1);
    for(ll i = 1;i <= n;i++) cin >> b[i];
    for(ll j = 1;j <= m;j++) cin >> c[j];
    g = graph();
    r = graph();
    s = 0;
    t = n+m+1;
    ans = 0;
    for(ll i = 1;i <= n;i++){
      for(ll j = 1;j <= m;j++){
        if(gcd(b[i],c[j]) > 1){
          g[i][n+j] = 1;
          r[n+j][i] = 0;
        }
      }
    }
    for(ll i = 1;i <= n;i++){
      g[s][i] = 1;
      r[i][s] = 0;
    }
    for(ll j = 1;j <= m;j++){
      g[n+j][t] = 1;
      r[t][n+j] = 0;
    }
    idx = t;
    for(;;){
      fill(vis,vis+(idx+1),0ll);
      fill(level,level+(idx+1),-1ll);
      bfs();
      // for(ll i = 0;i <= t;i++) cerr << level[i] << " ";
      // cerr << endl;
      if(level[t] < 0) break;
      for(;;){
        fill(vis,vis+(idx+1),0ll);
        ll z = dfs(s, INF);
        // cerr << " " << z << endl;
        if(z <= 0) break;
        ans += z;
      }

    }
    cout << ans << endl;
  }


}



Measured memory_bytes: 13020
// ░░░░░░░░( •̪●)░░░░░░░░░░░░░░░░░░░░░░░░
// ░░░░░░███████ ]▄▄▄▄▄▄▄▄▃░░░▃░░░░ ▃░
// ▂▄▅█████████▅▄▃▂░░░░░░░░░░░░░░░░░
// [███████████████████].░░░░░░░░░░░░░░
// ◥⊙▲⊙▲⊙▲⊙▲⊙▲⊙▲⊙◤...░░░░░░░░░░░░

//PointBlank's code (⌐■_■)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
 
ll power(ll x, ll y); 
#define repp(I, A, B) for(int I = A; I <= B; I++)
#define rep(I, A, B) for(int I = A; I < B; I++)
#define rrep(I, B, A) for(int I = B; I >= A; I--)
#define pb emplace_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define LB lower_bound
#define UB upper_bound
#define MP make_pair
#define mem(A, B) memset(A, B, sizeof(A));
#define mem0(A) memset(A, 0, sizeof(A));
#define quickio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(this) cerr<<"> "<<#this<<" : "<<this<<"\n"
#define bitcount(n) __builtin_popcountll(n)
#define in_edges(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B), v[B].pb(A);}
#define in_edges2(M) repp(I, 1, M){ll A, B; cin >> A >> B; v[A].pb(B);}
#define endl "\n"

const ll MOD = 1000000007;
 
int main() //PointBlank's code ¯\_(ツ)_/¯
{
    char ch;
    cin >> ch;
    if(ch <= 'Z' && ch >= 'A') cout << 'A';
    else cout << 'a';
}

ll power(ll x, ll y)
{ 
    ll res = 1; x %= MOD;
    while(y > 0){if(y & 1) res = (res*x) % MOD; y = y>>1, x = (x*x) % MOD;} 
    return res; 
}

Measured memory_bytes: 3632
import sys
N, M = map(int, sys.stdin.readline().rstrip().split())
H = list(map(int, sys.stdin.readline().rstrip().split()))
Route =[list(map(int, sys.stdin.readline().rstrip().split())) for i in range(M)]
cnt=0
l =[[] for i in range(N)]
for r in Route:
	l[r[0]-1].append(r[1])
	l[r[1]-1].append(r[0])
for i in range(N):
	for j in l[i]:
		if H[i]<= H[j-1]:break
	else:
		cnt+=1
print(cnt)

Measured memory_bytes: 41276
#include <iostream>


using namespace std;


int main()
{
  int a[212345], array[512345];
  int n;

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

  int left=212345, right=left+1;
  for (int i=0; i<n; i++){
    if ((i+1)%2 == n%2) array[left--] = a[i];
    else array[right++] = a[i];
  }

  for (int i=left+1; i<right; i++) cout << array[i] << ' ';
  cout << endl;

  return 0;
}


Measured memory_bytes: 4608
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>

using namespace std;
int main(int argc, char const *argv[])
{
    int n, a, b;
    cin >> n >> a >> b;

    int ret = b <= a*n ? b : a*n;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.{BufferedReader, InputStreamReader}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val n = in.readLine().toInt
    val s = in.readLine()

    System.out.println(
      s.toList.zip(s.toList.tail).count {
        case (a,b) => a != b
      } + 1
    )
  }
}


Measured memory_bytes: 44028
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
  int n;
  int c[4] = {0, 0, 0, 0};
  scanf("%d", &n);

  string str;
  for (int i = 0; i < n; i++) {
    cin >> str;
    if (str == "AC") {
      c[0]++;
    } else if (str == "WA") {
      c[1]++;
    } else if (str == "TLE") {
      c[2]++;
    } else
      c[3]++;
  }

  cout << "AC x " << c[0] << "\n";
  cout << "WA x " << c[1] << "\n";
  cout << "TLE x " << c[2] << "\n";
  cout << "RE x " << c[3] << "\n";
}


Measured memory_bytes: 3672
//Dragon_warrior7(IITK)
// #pragma GCC optimize("O0") 
// #pragma GCC optimize ("Ofast")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize ("-ffloat-store")
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define umap unordered_map
#define uset unordered_set
#define ll long long
//#define lll long long
#define pb push_back
#define nl cout << '\n'
#define sor(x) sort(x.begin(), x.end())
#define rev(v) reverse(v.begin(), v.end())
#define lb(v, temp) lower_bound(v.begin(), v.end(), temp)
#define ub(v, temp) upper_bound(v.begin(), v.end(), temp)
#define fi first
#define se second
#define llmax 1000000000000000000
#define pll pair<ll, ll> 
//#define ull unsigned ll
#define vll vector<ll>
#define vpll vector<pll> 
#define rub cerr << "\n------------------------------------\n"
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
#define fo(i,a,b) for(int i=a;i<b;i++)
#define Lets_be_precise cout<<fixed<<setprecision(10)
//typedef  tree < int ,  null_type ,  greater<int> ,  rb_tree_tag ,  tree_order_statistics_node_update > oset;
// const int mod=1e9+7;
// ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// ll modInverse(ll a){return power(a,mod-2);}
ll n,m,a,b,c,k,temp,x,y;
const int MAXN=100000+11;
void read(vector<ll> &v)
{for (int i = 0; i < v.size(); i++)cin>>v[i];}
inline ll max(ll a,ll b)
{return ((a>b)?a:b);}
inline ll min(ll a,ll b)
{return ((a>b)?b:a);}
inline ll int gcd(ll int a ,ll int b)
{if(b==0) return a;a%=b;return gcd(b,a);}
//#define cerr if(false)cerr//uncomment to remove cerr from program...
void solveforthiscase(const int & test)
{//deb(test);
int count=0;
cin>>n;
ll sum=0;
ll val=1;
for(ll i=1;i<=n;i++)
{
    if(i%3==0 || i%5==0)
    continue;
    sum+=i;
    count++;
    if(count==n)
    break;
}
cout<<sum;
return ;
}

int main()
{
	ios_base::sync_with_stdio(false);
	Lets_be_precise;
	cin.tie(NULL);
	cout.tie(NULL);
	int test=1;
// 	cin>>test;
    for(int i=1;i<=test;i++)
    {
        solveforthiscase(i);
    }
}

Measured memory_bytes: 3616
//main関数

#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int a,b;
	cin>>a>>b;
	vector<vector<char>> p(a,vector<char>(b));
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			cin>>p.at(i).at(j);
		}
	}
	vector<bool> A(a,true);
	vector<bool> B(b,true);
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			if(p.at(i).at(j)=='#'){
				A.at(i)=false;
				B.at(j)=false;
			}
		}
	}
	for(int i=a-1;i>=0;i--){
		if(A.at(i)){
			for(int j=i+1;j<a;j++){
				p.at(j-1)=p.at(j);
			}
			a-=1;
		}
	}
	for(int i=b-1;i>=0;i--){
		if(B.at(i)){
			for(int j=0;j<a;j++){
				for(int k=i+1;k<b;k++){
					p.at(j).at(k-1)=p.at(j).at(k);
				}
			}
			b-=1;
		}
	}
	for(int i=0;i<a;i++){
		for(int j=0;j<b;j++){
			cout<<p.at(i).at(j);
		}
		cout<<endl;
	}			
}

Measured memory_bytes: 256
function main(input){
  const lines = input.split('\n');
  const N = lines[0].split(' ').map(x => parseInt(x))[0];
  const K = lines[0].split(' ').map(x => parseInt(x))[1];
  const A = lines[1].split(' ').map(x => parseInt(x)).sort();

  const size_sorted_A = [];
  var current_number = A[0];
  var count = 1;
  for(var i = 1;i<=A.length;i++){
    if(A[i]==current_number){
      count++;
    }else{
      size_sorted_A.push(count);
      count=1;
    }
    current_number = A[i];
  }
//console.log('---')
//console.log(size_sorted_A)

  size_sorted_A.sort((a, b) => a - b);
//console.log(size_sorted_A)

  var result = 0;

  if(size_sorted_A.length <= K){
    console.log(result);
    return;
  }

  for(var i=0;i<size_sorted_A.length;i++){
    var size = size_sorted_A[i];
    result+=size;
    if(size_sorted_A.length-(i+1) <= K){
      console.log(result);
      return;
    }
//console.log(size_sorted_A)
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));



Measured memory_bytes: 37548
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)

#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)

#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)

#define mem(a,n) memset( a, n, sizeof(a))
typedef long long ll;
const int INF = 1e9;
const ll LLINF = 1e18;

int main() {
    int N, x;
    cin>>N>>x;
    
    int nums[N+5], nums2[N+5];
    rep(i,N){
        int x;
        cin>>x;
        nums[i]=x;
        nums2[N-1-i]=x;
    }
    
    ll cnt=0;
    if(nums[0]>x){
        cnt += nums[0]-x;
        nums[0] = x;
    }
    
    rep(i,N-1){
        if(nums[i]+nums[i+1]>x){
            cnt += nums[i]+nums[i+1]-x;
            nums[i+1] -= nums[i]+nums[i+1]-x;
        }
    }
    cout1(cnt);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <math.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REPR(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define FOR(i, n, m) for (ll i = (n); i < (m); ++i)
#define FORR(i, n, m) for (ll i = (m) - 1; i >= (n); --i) 
#define FORE(x, xs) for (auto &x: (xs))
#define ALL(v) v.begin(), v.end()
#define ZERO(a) memset(a,0,sizeof(a))

const int INF = 1000000009;
const int MOD = 1000000007;
const double EPS = 1e-14;
const double PI = acos(-1);

const int MAX = 2e5;

ll H, W;
int *red[500], *blue[500];

void show(int **f) {
  REP (h, H) {
    string line = "";
    REP (w, W) line += (f[h][w]) ? '#' : '.';
    cout << line << endl;
  }
}

int main() {
  cin >> H >> W;

  REP (h, H) {
    red[h] = new int[500];
    blue[h] = new int[500];
    REP (w, W) {
      red[h][w] = h%2;
      blue[h][w] = 1-red[h][w];
    }
    red[h][0] = blue[h][W-1] = 1;
    red[h][W-1] = blue[h][0] = 0;
  }

  REP (h, H) {
    string s;
    cin >> s;
    REP (w, W) 
      if (s[w] == '#') red[h][w] = blue[h][w] = 1;
  }

  show(red);
  cout << endl;
  show(blue);


  return 0;
}

Measured memory_bytes: 2688
import sys
sys.setrecursionlimit(10**6)
n, q = map(int, input().split())

edge = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    edge[a].append(b)
    edge[b].append(a)

imos = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    p -= 1
    imos[p] += x

q = [(0, -1)]
while q:
    v, p = q.pop()
    for u in edge[v]:
        if u == p:
            continue
        imos[u] += imos[v]
        q.append((u, v))

print(' '.join([str(x) for x in imos]))


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;

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

const ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n; cin>>n;
  vll a(n);
  rep(i,n) cin>>a[i];
  
  deque<ll> d;
  rep(i,n){
    auto itr=lower_bound(all(d),a[i]);
    if(itr==d.begin()) d.push_front(a[i]);
    else{
      ll j=itr-d.begin()-1;
      d[j]=a[i];
    }
  }
  cout<<d.size()<<endl;
}

Measured memory_bytes: 1920
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[][] a = new int[n+1][n+1];
        for(int i = 0; i < n; i++){
            int u = Integer.parseInt(sc.next());
            int k = Integer.parseInt(sc.next());
            for(int j = 0; j < k; j++){
                int v = Integer.parseInt(sc.next());
                a[u][v] = 1;
            }
        }
        
        StringBuilder sb = new StringBuilder();
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                sb.append(a[i][j]).append(" ");
            }
            sb.deleteCharAt(sb.length()-1);
            sb.append(System.lineSeparator());
        }
        System.out.print(sb);
    }
}


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

int main()
{
    int N;
    cin >> N;

    string S;
    cin >> S;

    int K;
    cin >> K;

    char c = S.at(K - 1);

    for(int i= 0; i < N; i++)
    {
        if(S.at(i) != c)
        {
            S.at(i) = '*';
        }
    }

    cout << S << endl;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[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()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        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)*}
    };
}

#[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, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input!{
        n: usize,
        q: usize,
        edges: [(usize, usize); n-1],
        points: [(usize, i64); q]
    }
    let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
    for (a, b) in edges {
        graph[a-1].push(b-1);
        graph[b-1].push(a-1);
    }
    let mut add_values: Vec<i64> = vec![0; n];
    for (v, p) in points {
        add_values[v-1] += p;
    }
    let mut total_points: Vec<i64> = vec![0; n];
    let mut dist: Vec<bool> = vec![false; n];
    let mut que: VecDeque<usize> = VecDeque::new();
    dist[0] = true;
    que.push_front(0);
    while !que.is_empty() {
        let p = match que.pop_front() {
            Some(x) => x,
            _ => 0
        };
        total_points[p] += add_values[p];
        for v in &graph[p] {
            if dist[*v] {continue;}
            dist[*v] = true;
            total_points[*v] += total_points[p];
            que.push_front(*v);
        }
    }

    print!("{}", total_points[0]);
    for i in 1..n {
        print!(" {}", total_points[i]);
    }
    println!("");
}


Measured memory_bytes: 26876
/*
7 7
1 3
2 7
3 4
4 5
4 6
5 6
6 7
0 2
1 6
2 0 3
3 2 4 5
4 3 5
5 3 4 6
6 1 5
*/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
//One-Stroke Path
int main(){
  int N, M;
  cin >> N >> M;
  //道の入力
  vector<pair<int, int>> p;
  for(int i = 0; i < M; i++){
    int fst, sec;
    cin >> fst >> sec;
    fst --;
    sec --;
    p.push_back(make_pair(fst, sec));
  }
  //道をあるノードから伸びてるかどうかで多重配列
  vector<vector<int>> path;
  for(int i = 0; i < N; i++){
    //配列を作って道があるか回してから突っ込む
    vector<int> dest;
    for(int j = 0; j < M; j++){
      if(p[j].first == i){
        dest.push_back(p[j].second);
      }
      else if(p[j].second == i){
        dest.push_back(p[j].first);
      }
    }
    path.push_back(dest);
  }
  //並び替えるノードの配列を作る
  vector<int> dot;
  for(int i = 1; i < N; i++){
    dot.push_back(i);
  }
  //何個通路あるか
  int count = 0;
  do{
    dot.insert(dot.begin(), 0);
    //dotの何番目の数を参照してるか
    for(int i = 0; i < N-1; i++){
      //次の数があるかどうか
      bool ok = false;
      //参照してるdotの数のpathの配列の中に次の数があるか
      int num = dot[i];
      for(int j = 0; j < path[num].size(); j++){
        if(path[num][j] == dot[i+1]){
          ok = true;
          break;
        }
      }
      if(!ok){
        break;
      }
      if(i == N-2){
        count ++;
      }
    }
    dot.erase(dot.begin());
  }while(next_permutation(dot.begin(), dot.end()));
  cout << count <<endl;
}

Measured memory_bytes: 256
main(n){double x1,y1,x2,y2,x3,y3,a1,b1,c1,a2,b2,c2,x,y;for(scanf("%d",&n);n--;printf("%.3f %.3f %.3f\n",x,y,hypot(x1-x,y1-y)))scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3),a1=2*x2-2*x1,b1=2*y2-2*y1,c1=x1*x1-x2*x2+y1*y1-y2*y2,a2=2*x3-2*x1,b2=2*y3-2*y1,c2=x1*x1-x3*x3+y1*y1-y3*y3,x=(b1*c2-b2*c1)/(a1*b2-a2*b1),y=(c1*a2-c2*a1)/(a1*b2-a2*b1);exit(0);}

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const long long MOD = 1e9 + 7;
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;
}

///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    double R; cin >> R;
    double pi = 3.1415926535897932;
    cout << 2 * pi * R << endl;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    long long int a,b,k;
	cin>>a>>b>>k;
	if(k>0 && k>=a)
	{
		k-=a;
		a=0;
	}
	else
    {
      a-=k;
      k=0;
    }
	if(k>0 && k>=b)
	{
		k-=b;
		b=0;
	}
	else
	b-=k;
	printf("%lld %lld",a,b);
}

Measured memory_bytes: 3752
/*
ID: jerrywcy
TASK: AtCoder ABC 108 Problem A
LINK: https://abc108.contest.atcoder.jp/tasks/abc108_a
LANG: C++
*/
#include <iostream>

using namespace std;

int x1,y1,x2,y2;
int x3,y3,x4,y4;

int main()
{
	cin>>x1>>y1>>x2>>y2;
	
	int xx=x2-x1,yy=y2-y1;
	
	x3=x2-yy,y3=y2+xx;
	x4=x3-xx,y4=y3-yy;
	
	cout<<x3<<' '<<y3<<' '<<x4<<' '<<y4<<endl;

	return 0;
}



Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
#define set(x) cout<<fixed<<setprecision(x);
using namespace std;
//**********************************************DO IT NO****************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       int c=0,m=-1;
       while(n--)
       {
           int x,y;
           cin>>x>>y;
           if(x==y)
           c++;
           else
           {
               if(c>m)
               m=c;
               c=0;
           }
       }
       if(c>m)
       m=c;
       if(m>=3)
       cout<<"Yes";
       else
       cout<<"No";
      // cout<<m;
}
}
// 🍪 🍪 🍪


Measured memory_bytes: 3608
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace A_project
{
    class Program
    {
        static void Main(string[] args)
        {
           string input = ReadLine();
            string[] array = input.Split(' ');
            int[] figure = new int[array.Length];
            for (int i = 0; i < array.Length; i++) {
                figure[i] = int.Parse(array[i]);
            }
            int result = figure[0] * figure[1] % 2;
            if (result == 0)
            {
                WriteLine("Even");
            }
            else {
                WriteLine("Odd");
            }
            ReadKey();
        }
    }

}


Measured memory_bytes: 11220
L, R = map(int, input().split())
if R // 2019 - (L - 1) // 2019 != 0:
    print(0)
else:
    minnum = 5000
    Lmod = L % 2019
    Rmod = R % 2019
    for i in range(Lmod, Rmod+1):
        for j in range(i + 1, Rmod+1):
            #print(i, j, (i * j) % 2019)
            minnum = min(minnum, (i * j) % 2019)
    print(minnum)


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

typedef  long long ll;
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;}

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep2(i, begin_i, end_i) for (int i = (int)begin_i; i < (int)end_i; i++)

long long INF = 1LL<<60;
long long dp[100010];
int h[100010];
int n;
ll gcd(ll a,ll b){
    if(a%b==0)return b;
    else{
        return gcd(b,a%b);
    }
}
int main(){
    ll a,b;
    cin>>a>>b;
    ll div=gcd(a,b);
    cout<<a*b/div<<endl;
    return 0;
}




Measured memory_bytes: 256
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(sorted(AB, key=lambda x: x[0], reverse=False), key=lambda x: x[1], reverse=True)
x = [0] * M
p = [x for x in range(M)]

cnt = 0
cntIN = M
for a, b in AB:
    i = M-a

    s = []
    while i >= 0 and p[i] != i:
        s.append(i)
        i = p[i]
    for j in s:
        p[j] = i - 1

    if i >= 0:
        x[i] = b
        p[i] = i - 1
        cntIN -= 1            
        if cntIN <= 0:
            break

print(sum(x))


Measured memory_bytes: 76376
#include<stdio.h>
int main(){
  char s[102];
  char w;
  int i;
  while(scanf(" %s %c",s,&w),w!='X'){
    if(w=='U')printf("%c",toupper(s[0]));
    else      printf("%c",tolower(s[0]));
    for(i=1;s[i];i++){
      if('a'<=s[i]&&s[i]<='z'){
	printf("%c",s[i]);
      }
      else{
	if(s[i]=='_')i++;
	if(w=='D')printf("_%c",tolower(s[i]));
	else      printf("%c" ,toupper(s[i]));
      }
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define all(x) (x).begin(), (x).end()
#define MOD 1000000007
vector<double> Dijkstra_list(int n, int s,
                             vector<vector<pair<double, double>>> &Edge) {
    vector<bool> visited(n, false); //確定済み
    vector<double> d(n, DBL_MAX);
    priority_queue<pair<double, double>, vector<pair<double, double>>,
                   greater<pair<double, double>>>
        que; //頂点とsからの距離
    d[s] = 0;
    que.push(make_pair(0, s));
    while(!que.empty()) {
        auto now = que.top();
        que.pop();
        visited[now.second] = true;
        for(auto e : Edge[now.second]) {
            if(visited[e.second])
                continue;
            if(d[e.second] > d[now.second] + e.first) {
                d[e.second] = d[now.second] + e.first;
                que.push(make_pair(d[e.second], e.second));
            }
        }
    }
    return d;
}
double dis(double x, double y, double v, double w, double r1, double r2) {
    double tmp = sqrt((x - v) * (x - v) + (y - w) * (y - w));
    return max(0.0, tmp - r1 - r2);
}
int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> cake(h);
    vector<int> noth;
    for(int i = 0; i < h; i++) {
        cin >> cake[i];
    }
    int p = 1;
    vector<vector<int>> ans(h, vector<int>(w, -1));
    for(int i = 0; i < h; i++) {
        if(count(all(cake[i]), '#') == 0) {
            noth.push_back(i);
            continue;
        } else {
            for(int j = 0; j < w; j++) {
                ans[i][j] = p;
                if(cake[i][j] == '#') {
                    p++;
                }
            }
            p--;
            int k = w - 1;
            while(cake[i][k] != '#') {
                ans[i][k] = p;
                k--;
            }
            p++;
        }
    }
    for(int i = 0; i < h - 1; i++) {
        if(ans[i][0] != -1 && ans[i + 1][0] == -1) {
            ans[i + 1] = ans[i];
        }
    }
    for(int i = h - 1; i >= 1; i--) {
        if(ans[i][0] != -1 && ans[i - 1][0] == -1) {
            ans[i - 1] = ans[i];
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            cout << ans[i][j] << " ";
        }
        cout << endl;
    }
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,a=0;
  cin>>n;
  int p[55];
  for(int i=0;i<n;++i)cin>>p[i];
  for(int i=1;i<n+1;++i){
    if(p[i-1]!=i)a+=1;
  }
  if(a<=2)cout<<"YES";
  else cout<<"NO";
}

Measured memory_bytes: 256
import java.io.*;
import  java.util.*;

import static java.lang.System.in;

class Main{
    public static void main(String[] args)throws IOException{
        Scanner sc = new Scanner(System.in);
        int[][] res = new int[3][];
        int a = sc.nextInt(), b=sc.nextInt(), c=sc.nextInt();
        res[0] = new int[]{a,b,3*c-b-a};
        res[1] = new int[]{4*c-2*a-b,c,2*a+b-2*c};
        res[2] = new int[]{a+b-c,2*c-b,2*c-a};
        for(int i=0;i<3;i++){
            String ans="";
            for(int j=0;j<3;j++) ans = ans+Integer.toString(res[i][j])+" ";
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 21844
#include <time.h>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
int main(int argc, char const *argv[]) {
  ll N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> l(Q);
  vector<int> r(Q);
  for (size_t i = 0; i < l.size(); i++) {
    cin >> l[i] >> r[i];
  }
  vector<int> ACpair(N, 0);
  for (size_t i = 0; i < S.size()-1; i++) {
    ACpair[i + 1] = ACpair[i];
    if (S[i] == 'A') {
      if (S[i + 1] == 'C') {
        ACpair[i + 1]++;
      }
    }
  }
  for (size_t i = 0; i < l.size(); i++) {
    cout << ACpair[r[i]-1] - ACpair[l[i]-1] << endl;
  }

  return 0;
}


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

int main(){
    int A,B;
    int K;
    int judge = 0;
    cin >> K;
    cin >> A >> B;
    for(int i = A; i <= B;i++){
        if(i%K == 0)judge++;
    }
    if(judge >0 ){
        cout << "OK" <<endl;
    }else{
        cout << "NG" <<endl;
    }

}

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

pair<long, long> divide(long h, long w) {
  long s = h * w;
  if (s % 2 == 0) return make_pair(s / 2, s / 2);
  if (h > w) swap(h, w);
  long s1 = h * (w / 2);
  return make_pair(s1, s - s1);
}

int main() {
  long h, w, ans = 1l << 62;
  cin >> h >> w;
  if (h % 3 == 0 || w % 3 == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (long i = h / 3 - 1; i <= h / 3 + 2; i++) {
    long s = i * w, s1 = divide(h - i, w).first, s2 = divide(h - i, w).second;
    ans = min(ans, max(abs(s - s1), max(abs(s1 - s2), abs(s - s2))));
  }
  for (long i = w / 3 - 1; i <= w / 3 + 2; i++) {
    long s = i * h, s1 = divide(w - i, h).first, s2 = divide(w - i, h).second;
    ans = min(ans, max(abs(s - s1), max(abs(s1 - s2), abs(s - s2))));
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
MOD = 1000000007
h,w=map(int,input().split())
graph=[]
for i in range(h):
  graph.append(list(input()))
#print(graph)
dp=[[0]*(w) for _ in range(h)]
dp[0][0]=1
for i in range(1,w):
  if graph[0][i]=='#':
    break
  dp[0][i]=1
for i in range(1,h):
  if graph[i][0]=='#':
    break
  dp[i][0]=1
for i in range(1,h):
  for j in range(1,w):
    #print(i-1,j-1)
    if(graph[i][j]=='#'):
      dp[i][j]=0
    else:
      dp[i][j]=(dp[i-1][j]+dp[i][j-1])%MOD

print(dp[-1][-1])

Measured memory_bytes: 116876
a,b = map(int,input().split())

list = [2,3,4,5,6,7,8,9,10,11,12,13,1]

if list.index(a) > list.index(b):
  print('Alice')
elif list.index(a) == list.index(b):
  print('Draw')
else:
  print('Bob')

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, m;
  cin >> n >> m;
  
  vector<int> x(n);
  for (int i = 0; i < n; i++) cin >> x.at(i);
  
  sort(x.begin(), x.end());
  
  map<int, int> mp1, mp2;
  // mp1[i]:mで割った余りがiのカードが何枚あるか
  // mp2[i]:mで割った余りがiのカードだけで同じ整数をペアにしたとき, 最大何ペアできるか
  for (int i = 0; i < n; i++) mp1[x.at(i) % m]++;
  int count = 1;
  for (int i = 1; i < n; i++) {
    if (x.at(i - 1) == x.at(i)) count++;
    else {
      mp2[x.at(i - 1) % m] += count / 2;
      count = 1;
    }
  }
  mp2[x.back() % m] += count / 2;
  
  int ans = 0;
  for (int i = 0; i <= m / 2; i++) {
    if (i == 0 || (m % 2 == 0 && i == m / 2)) {
      ans += mp1[i] / 2;
    }
    else {
      int keep = min(mp1[i], mp1[m - i]);
      ans += keep;
      mp1[i] -= keep;
      mp1[m - i] -= keep;
      if (mp1[i] > 0) {
        ans += min(mp1[i] / 2, mp2[i]);
      }
      else if (mp1[m - i] > 0) {
        ans += min(mp1[m - i] / 2, mp2[m - i]);
      }
    }
  }
  
  cout << ans << '\n';
}

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

const int N = 1e5 + 5, mod = 1e9 + 7, inf = INT_MAX;

int par[N], rnk[N];
ll siz[N];

int findp(int x)
{
    return (par[x] == x? x: par[x] = findp(par[x]));
}

bool iscon(int x, int y)
{
    return (findp(x) == findp(y));
}

void con(int x, int y)
{
    int px = findp(x), py = findp(y);
    if (rnk[px] > rnk[py])
        siz[px] += siz[py],
                par[py] = px;
    else if (rnk[px] < rnk[py])
        siz[py] += siz[px],
                par[px] = py;
    else
        siz[py] += siz[px],
                par[px] = py, rnk[px]++;
}

int main()
{
    //ios::sync_with_stdio(false);cin.tie(nullptr);ios_base::sync_with_stdio(false);
    ll n, m;
    pair<int, int> a[N];
    cin >> n >> m;
    ll beg = n * (n - 1) / 2;
    for (int i = 1; i <= n; i++)
        siz[i] = 1, par[i] = i;
    stack<ll> s;
    for (int i = 0; i < m; i++)
        cin >> a[i].first >> a[i].second;
    for (int i = m--; i > -1; i--)
    {
        if (!iscon(a[i].first, a[i].second))
            beg -= siz[findp(a[i].first)] * siz[findp(a[i].second)],
                    con(a[i].first, a[i].second);
        s.push(beg);
    }
    s.pop();
    while (!s.empty())
        cout << s.top() << endl,
                s.pop();
    return 0;
}

Measured memory_bytes: 6980
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const int inf = 1e9+7;
const int N = 1e6+9;
int A[N];

void solve() {
    int a, b, n, k;
    cin>>n>>k;
    for(int i=0;i<n;++i) {
        cin>>A[i];
    }
    sort(A, A+n);
    ll s=0;
    for(int i=0;i<k;++i) s+=A[i];
    cout<<s<<endl;
}
int main() {
    ios_base::sync_with_stdio(0);
    int T=1 ,cas=0;
    while(T--) {
        solve();
    }
    return 0;
}

// ll, reset, 1, bottom

Measured memory_bytes: 3660
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <forward_list>
#include <random>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define lcm( a, b ) (a)/__gcd((a),(b))*(b)
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const LL MOD = 998244353;
static const int SIZE = 200005;

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

vector< int > Div( int n ) {
    vector< int > ret;
    for( int i = 1; i * i <= n; ++i ) {
        if( n % i == 0 ) {
            ret.pb( i );

            if( i * i != n ) ret.pb( n / i );
        }
    }
    sort( all( ret ) );
    return ret;
}

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

    int n;
    cin >> n;
    int d[SIZE];
    for( int i = 1; i <= n; ++i ) {
        cin >> d[i];

    }

    if( d[1] != 0 ) {
        cout << 0 << endl;
        return 0;

    }

    for( int i = 2; i <= n; ++i ) {
        if( d[i] == 0 ) {
            cout << 0 << endl;
            return 0;

        }
    }

    LL dist[SIZE] = {};
    for( int i = 1; i <= n; ++i ) {
        dist[d[i]]++;

    }

    int mx = 0;
    for( int i = 1; i < SIZE; ++i ) {
        if( dist[i] != 0 ) mx = i;
        
    }

    if( mx == 1 ) {
        cout << 1 << endl;
        return 0;

    }

    LL res = 1;
    for( int i = 1; i < SIZE; ++i ) {
        if( dist[i] != 0 && dist[i - 1] == 0 ) {
            cout << 0 << endl;
            return 0;

        }

        if( dist[i - 1] == 0 ) continue;
        LL tmp = dist[i - 1];
        for( int j = 0; j < dist[i] - 1; ++j ) {
            tmp *= dist[i - 1];
            tmp = tmp % MOD;

        }
        if( dist[i] == 0 ) tmp = 1;
        res = (res * tmp) % MOD;

    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 2560