akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
	int A[4][3][10]={0};
	int b,f,r,v;
	int n,i,j,k;
	
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d %d %d %d",&b,&f,&r,&v);
		A[b-1][f-1][r-1]+=v;
		//printf("%d\n",A[b-1][f-1][r-1]);
	}
	
	for(i=0;i<4;i++){
		//printf("%dtou\n",i+1);
		for(j=0;j<3;j++){
			//printf("%dkai\n",j+1);
			for(k=0;k<10;k++){
				//printf("%dgousitu\n",k+1);
				printf(" %d",A[i][j][k]);
			}
			printf("\n");
		}
		if(i<3)printf("####################\n");
	}
	return 0;
}

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

int main() {
  int N, nx, n;
  cin >> N;
  
  nx = N / 100000000;
  n = N % 100000000;
  nx += n / 10000000;
  n = n % 10000000;
  nx += n / 1000000;
  n = n % 1000000;
  nx += n / 100000;
  n = n % 100000;
  nx += n / 10000;
  n = n % 10000;
  nx += n / 1000;
  n = n % 1000;
  nx += n / 100;
  n = n % 100;
  nx += n / 10;
  nx += n % 10;
  
  if( N % nx == 0 )
    cout << "Yes" << endl;
  else
    cout << "No" << endl;  
}


Measured memory_bytes: 256
def cumsum(mydata):
    cumsum = [0]*(len(mydata)+1)
    cumsum[0] = 0
    for i in range(len(mydata)):
        cumsum[i+1] = cumsum[i] + mydata[i]
    return cumsum

def main():
    n,m,q = map(int,input().split())
    train_ls = [[0 for _ in range(n)] for _ in range(n)]
    for _ in range(m):
        l,r = map(int,input().split())
        train_ls[r-1][l-1] += 1
    cumsums = []
    for i in range(n):
        cumsums.append(cumsum(train_ls[i]))
    
    q_ls = [[int(x) for x in input().split()] for _ in range(q)]
    for left,right in q_ls:
        ans = 0
        for i in range(left,right+1):
            ans += cumsums[i-1][right] - cumsums[i-1][left-1]
        print(ans)
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 78936
#include <stdio.h>
int main()
{
    int A,B;
    scanf("%d%d",&A,&B);
    if ((A==2&&B==3)||(A==3&&B==2))
        printf("1");
    else if ((A==1&&B==3)||(A==3&&B==1))
        printf("2");
    else
        printf("3");
    return 0;
}


Measured memory_bytes: 128
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  n <- getInt
  s <- BS.getLine

  let nR = BS.length $ BS.filter (== 'R') s
      s' = BS.drop nR s
      ans = BS.length $ BS.filter (== 'R') s'

  print ans


Measured memory_bytes: 4600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e6 + 100;
char s[N];


int main() {
   scanf("%s", s);
   int len = strlen(s);
   int ans = 0;
   int add = 0, flag = 0;
   for(int i=len-1;i>=0;i--) {
        if(flag) {

                if(s[i] >= '5') {
                    flag = 0;
                    add = 1;
                    ans += (10 - (s[i] - '0') - 1);
                }else {
                    add = 0;
                    flag = 0;
                    ans += (s[i] - '0');
                }

        }else {
            if(s[i] == '9' && add == 1) {
                add = 1;
                flag = 0;
            }else {
                s[i] = s[i] + add;
                // cout<<s[i]<<endl;
                if(s[i] == '5') {
                    flag = 1;
                    add = 0;
                    ans += 5;
                }else if(s[i] > '5') {
                    add = 1;
                    flag = 0;
                    ans += (10 - (s[i]-'0'));
                }else {
                    add = 0;
                    flag = 0;
                    ans += (s[i] - '0');
                }
            }
        }
   }
   ans += add;
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define ll long long
#define INF 1000000007

ll f[1000001];

ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a;
 while(b > 0)
 	{
 		if(b%2 == 1)
 	{
 		x=(x*y);
 		if(x>MOD) x%=MOD;
 	}
 	y = (y*y);
 	if(y>MOD) y%=MOD;
 	b /= 2;
 	}
 return x;
}

ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}

ll C(ll n, ll r, ll MOD)
{

 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}

int main(){
	f[0] = 1;
	for(int i = 1 ; i <= 1000000 ; i++)
		f[i] = (f[i-1]*i)%INF;
    ll x, y;
    cin >> x >> y;
    ll a = (x + y) / 3;
    ll b = 2 * a - x;
    if((x + y) % 3 || b > a || b < 0)
    {
        cout << 0;
        return 0;
    }
 	cout << C(a, b,INF);
}


Measured memory_bytes: 8064
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1000000007;
const ll N=998244353;
ll power(ll x,ll n){ll res=1;while(n>0){if(n&1) res=res*x%MOD;x=x*x%MOD;n>>=1;}return res;}
ll modinverse(ll a){return power(a, MOD-2);}
void solve()
{
    ll n, k;
    cin>>n>>k;
    vl a(n);
    forr(i, n)
    {
    	cin>>a[i];
    	a[i]--;
    	a[i]%=k;
    }
    ll currsum=0, ans=0;
    map<ll, ll> mp1, mp2;
    forr(i, n)
    {
    	currsum+=a[i];
    	if(i>=k-1)
    	{
    		ll num=mp2[i-k];
    		mp1[num]--;
    		if(mp1[num]==0)
    			mp1.erase(num);
    	}
    	currsum%=k;
    	if(currsum==0)
    		ans++;
    	if(mp1.find(currsum)!=mp1.end())
    	{
    		ans+=mp1[currsum];
    	}
    	mp1[currsum]++;
    	mp2[i]=currsum;
    }
    cout<<ans<<endl;
}
int main()
{
	#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll test=1;
    //cin>>test;
    while(test--)
    {
        solve();
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 29848
#include <iostream> 
#include <vector> 
#include <algorithm> 
#include <climits>
using namespace std;
using P = pair<int,int>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int x,y,z;
  cin >> x >> y >> z;
  int ans = 0;
  for(int i=1; i<=x; i++){
    if((long long)y*i + z*(i+1) <= x){
      ans = i;
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 3648
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: usize,
        a: [i32; n],
    }
    let mut a = a;
    let mut count = 0;
    loop {
        let odd = a.iter().any(|x| x % 2 != 0);
        if odd {
            break;
        }
        for a in &mut a {
            *a /= 2;
        }
        count += 1;
    }
    println!("{}", count)
    // let all_even = a.iter().all(|x| x % 2 == 0);
    // let min = a.iter().fold(std::i32::MAX, |a, &b| ::std::cmp::min(a, b));
    // println!("{}", (min as f64).log(2.0) as i32 - 1);
}


Measured memory_bytes: 4352
<?php
$input = trim(fgets(STDIN));
$A_point = array();
$Z_point = array();
for($i = 0; $i < strlen($input); $i++){
	switch($input[$i]){
		case 'A':
			$A_point[] = $i;
			break;
		case 'Z':
			$Z_point[] = $i;
			break;
		default:
	}
}
echo max($Z_point) - min($A_point) + 1;
?>

Measured memory_bytes: 32304
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

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

  if(A * B % 2 == 0)
    cout << "No\n";
  else
    cout << "Yes\n";
  
  return 0;
}


Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<queue>
#include<complex>
#include<numeric>
#include<bitset>
#define INF 1001001001
#define EPS 0.000000001
#define x first
#define y second

using namespace std;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int,int> pint;

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

int nextInt(){
	int x;
	scanf("%d",&x);
	return x;
}

int main(){
	while(1){
		int w = nextInt();
		int h = nextInt();
		if(w==0 && h==0) break;
		int i,j;
		
		int maze[40][40][4];
		memset(maze, 0, sizeof(maze));
		
		for(j=0; j<w-1; j++){
			int w = nextInt();
			if(w==0){
				maze[0][j][3]=1;
				maze[0][j+1][1]=1;
			}
		}
		for(i=0; i<h-1; i++){
			for(j=0; j<w; j++){
				int w = nextInt();
				if(w==0){
					maze[i][j][2]=1;
					maze[i+1][j][0]=1;
				}
			}
			for(j=0; j<w-1; j++){
				int w = nextInt();
				if(w==0){
					maze[i+1][j][3]=1;
					maze[i+1][j+1][1]=1;
				}
			}
		}
		
		int memo[40][40];
		for(i=0; i<40; i++) for(j=0; j<40; j++) memo[i][j]=-1;
		memo[0][0]=1;
		
		queue<pint> q;
		q.push(pint(0, 0));
		int f=0;
		while(!q.empty() && f==0){
			pint p = q.front(); q.pop();
			for(i=0; i<4; i++){
				if(maze[p.x][p.y][i]==1){
					if(memo[p.x+dx[i]][p.y+dy[i]]==-1){
						if(p.x+dx[i]==h-1 && p.y+dy[i]==w-1){
							f=memo[p.x][p.y]+1;
						}
						memo[p.x+dx[i]][p.y+dy[i]]=memo[p.x][p.y]+1;
						q.push(pint(p.x+dx[i], p.y+dy[i]));
					}
				}
			}
		}
		
		printf("%d\n", f);
		
				
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
vector<int>v;
map<int,int>mp;
set<int>st;
set<int> :: iterator it;

int main()
{
    int n,m,a,b,i,j,x,y,sum,k;

    while(scanf("%d",&n)==1)
    {
        mp.clear();
        v.clear();
        for(i=1;i<=n;i++)
        {
            scanf("%d",&a);
            v.push_back(a);
        }

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

        sum = 0;

        for(i=0;i<v.size();i++)
        {
            for(j=0;j<v.size();j++)
            {
                for(k=0;k<v.size();k++)
                {
                    if(i<j&&j<k&&v[i]!=v[j]&&v[i]!=v[k]&&v[j]!=v[k]&&v[i]+v[j]>v[k])
                    {
                        sum++;
                    }
                }
            }
        }

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










return 0;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
#include <chrono>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repl(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define rep2l(i, s, n) for (ll i = (ll)(s); i < (ll)n; i++)

int main() {
    string T;
    cin >> T;
    string ans;
    rep(i, T.size()) {
        if (T[i] == '?') {
            ans += 'D';
        }
        else {
            ans += T[i];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3864
#include<stdio.h>
 
int main()
{
  int a,b,c,n,i;
  i = 0;
  scanf("%d %d %d",&a,&b,&c); 
   
   
  for(n = a;n <= b;n++){
    if(c % n == 0)
  i++;
}
    printf("%d\n",i);
     
     
return 0;
}


Measured memory_bytes: 1996
#include <iostream>

using namespace std;
double abs(double x,double y)
{
    if(x>=y)
    {
        return x-y;
    }
    else
    {
        return y-x;
    }
}
int n,i;
double t,a,x,minim,poz,val;
int main()
{
    cin>>n;
    cin>>t>>a;
    cin>>x;
    val=t-x*0.006;
    minim=abs(val,a);
    poz=1;
    for(i=2;i<=n;i++)
    {
        cin>>x;
        val=t-x*0.006;
        if(abs(val,a)<minim)
        {
            minim=abs(val,a);
            poz=i;
        }
    }
    cout<<poz;
    return 0;
}


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

public class Test
{
	public static void Main()
	{
		// your code goes here
	int []n=Console.ReadLine().Split().Select(int.Parse).ToArray();
	int []a=new int[n[0]];
	for(int i=0;i<n[1];i++){
    int []s=Console.ReadLine().Split().Select(int.Parse).ToArray();
    if(s[0]==1){a[s[1]-1]+=3;}
    if(s[1]==n[0]){a[s[0]-1]+=2;}
	}
	for(int i=0;i<a.Length;i++){
		if(a[i]==5){Console.WriteLine("POSSIBLE");return;}
	}	
{Console.WriteLine("IMPOSSIBLE");}
	
	
	}
}

Measured memory_bytes: 15968
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

void solve() {
  vi v(5);
  while (cin >> v[0], v[0]) {
    loop(i, 1, 5) cin >> v[i];
    vi w(4);
    rep(i, 5) {
      v[i]--;
      w[v[i]]++;
      if (v[i] == 0) w[3]++;
    }
    if ((w[0] > 0 && w[1] > 0 && w[2] > 0) || (v[0] == v[1] && v[1] == v[2] && v[2] == v[3] && v[3] == v[4])) {
      rep(i, 5) cout << 3 << endl;
      continue;
    }
    rep(i, 5) {
      cout << 2 - !!w[v[i] + 1] << endl;
    }
  }
}

Measured memory_bytes: 3068
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n; cin>>n;
    if(n%2!=0){
        cout<<0<<endl;
        return 0;
    }
    ll w=5;
    ll ans=0;
    while(1){
        ans+=n/(w*2);
        if(n/(w*2)==0)break;
        w*=5;
    }
    cout<<ans<<endl;
}



























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

using namespace std;

int n, x[200005], ans, ta, tb;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf("%d", &ta);
		x[ta] = i;
	}
	ta = 0;
	for (int i = 1; i <= n; i++) {
		if (x[i] > tb)
			ta++;
		else
			ta = 1;
		tb = x[i];
		ans = max(ans, ta);
	}
	printf("%d\n", n - ans);
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>

struct card
{
  char suit;
  int num;
  int order;
};

int main()
{
  int n, i, j, min, flg;
  char str[3];
  struct card m, a[36], b[36];

  scanf("%d", &n);
  for(i=0; i<n; i++)
    {
      scanf("%s", str);
      a[i].suit = str[0];
      a[i].num = atoi(&str[1]);
      a[i].order = i;

      b[i].suit = str[0];
      b[i].num = atoi(&str[1]);
      b[i].order = i;
    }

  //bubble
  for(i=0; i<n; i++)
    {
      for(j=n-1; j>i; j--)
	{
	  if(a[j].num< a[j-1].num)
	    {
	      m = a[j];
	      a[j] = a[j-1];
	      a[j-1] = m;
	    }
	}
    }
  flg=0;
  
  for(i=0; i<n; i++)
    {
      printf("%c%d", a[i].suit, a[i].num);
      if(i+1<n) printf(" ");
      if(i < n-1 && a[i].num == a[i+1].num)
	{
	  if(a[i+1].order < a[i].order) flg=1;
	}
    }
  printf("\n");
  if(flg == 0) printf("Stable\n");
  else printf("Not stable\n");

  
  //selection
  for(i=0; i<n; i++)
    {
      min=i;
      for(j=i; j<n; j++)
	{
	  if(b[j].num<b[min].num)
	    min = j;
	}
      if(min != i)
	{
	  m = b[i];
	  b[i] = b[min];
	  b[min] = m;
	}
    }
  flg=0;
  
  for(i=0; i<n; i++)
    {
      printf("%c%d", b[i].suit, b[i].num);
      if(i+1<n) printf(" ");
      if(i < n-1 && b[i].num == b[i+1].num)
	{
	  if(b[i+1].order < b[i].order) flg=1;
	}
    }
  printf("\n");
  if(flg == 0) printf("Stable\n");
  else printf("Not stable\n");

  return 0;
}

Measured memory_bytes: 612
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int a;
    cin >> a;
    set<int>st;
    st.insert(a);
    int cnt = 1;
    while(1){
        cnt++;
        if(a%2)a = 3*a+1;
        else a = a/2;
        if(st.count(a)){
            cout << cnt << endl;
            return 0;
        }else{
            st.insert(a);
        }
    }
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

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

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (n == 0 && m == 0) break;
    int cost[100][100];
    int time[100][100];
    rep (i, 100) rep (j, 100) cost[i][j] = time[i][j] = 1e9;
    rep (i, 100) cost[i][i] = time[i][i] = 0;
    rep (i, n) {
      int a, b, c, t;
      cin >> a >> b >> c >> t;
      --a;
      --b;
      cost[a][b] = min(cost[a][b], c);
      time[a][b] = min(time[a][b], t);
      cost[b][a] = min(cost[b][a], c);
      time[b][a] = min(time[b][a], t);
    }
    rep (k, m) rep (i, m) rep (j, m) {
      cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
      time[i][j] = min(time[i][j], time[i][k] + time[k][j]);
    }
    int k;
    cin >> k;
    rep (i, k) {
      int p, q, r;
      cin >> p >> q >> r;
      --p;
      --q;
      if (r == 0) cout << cost[p][q] << endl;
      else cout << time[p][q] << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1236
import collections

def counter_top(c, exclude):
  for a in c.most_common():
    if a[0] != exclude:
      return a
  return (object(), 0)

def conv_seq(seq, exclude=None):
  c = collections.Counter(seq)
  mc = counter_top(c, exclude)
  return sum(c.values()) - mc[1], mc[0]

input()
vals = list(map(int, input().split()))
s1, a = conv_seq(vals[::2])
s2, b = conv_seq(vals[1::2])
if a != b:
  print(s1 + s2)
else:
  s1_new, _ = conv_seq(vals[::2], exclude=b)
  s2_new, _ = conv_seq(vals[1::2], exclude=a)
  print(min(s1_new + s2, s1 + s2_new))

Measured memory_bytes: 17116
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define dump(x) cout << #x << " = " << (x) << endl;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define SP << " " <<
using namespace std;
using ll = long long;
using P = pair<ll, ll>;

#define int long long

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  if(N == 1) {
    cout << 1 << endl;
  } else {
    if(N % 2 == 0) {
      cout << 0.5 << endl;
    } else {
      float x = N + 1;
      float y = 2 * N;
      float ans = x / y;
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
tb,xb,yb = 0,0,0
for _ in range(n):
    ta,xa,ya = list(map(int, input().split()))
    tdiff = abs(ta-tb)
    mdiff = abs(xa-xb) + abs(ya-yb)
    if tdiff < mdiff or (tdiff + mdiff) & 1:
        print('No')
        exit()
    
    tb,xb,yb = ta,xa,ya

print('Yes')


Measured memory_bytes: 9112
w = input()
n = input()
kuji = [i for i in range(w)]
for i in range(n):
	a, b = map(int, raw_input().split(","))
	kuji[a-1], kuji[b-1] = kuji[b-1], kuji[a-1]
for i in kuji:
	print i+1

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

using namespace std;
using ll = long long;

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

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

    ll ans = 1000, n_stock, value;
    bool decreasing = true;
    for(int i = 1; i < n; ++i) {
        if(decreasing) {
            if(a[i] < a[i - 1]) {
                continue;
            } else {
                decreasing = false;
                n_stock = ans / a[i - 1];
                ans %= a[i - 1];
            }
        } else {
            if(a[i] > a[i - 1]) {
                continue;
            } else {
                decreasing = true;
                ans += n_stock * a[i - 1];
                n_stock = 0;
                value = 0;
            }
        }
    }
    ans += n_stock * a[n - 1];

    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 3744
if __name__ == '__main__':
	n,m = map(int,input().split())
	d = []
	for i in range(n):
		d.append([int(s) for s in input().split()])
		sum = 0
		for k in range(m):
			sum += d[i][k]
		d[i].append(sum)
	
	for i in range(n):
		for k in range(m+1):
			if k == m:
				print("%d" % d[i][k])
			else:
				print("%d" % d[i][k], end=" ")
	for i in range(m+1):
		sum = 0
		for k in range(n):
			sum += d[k][i]
		if i == m:
			print("%d" % sum)
		else:
			print("%d" % sum, end=" ")


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

int dp[310][310], ma[310][310];
char st[310][310];

int main(void)
{
    int H, W, ans;
    cin >> H >> W;

    for (int i = 0; i < H; i++)
        cin >> st[i];

    ans = 0;

    for (int n = 0; n < W - 1; n++) {
        for (int i = 0; i < H; i++)
            for (int j = 0; j < H; j++)
                ma[i + 1][j + 1] = ma[i][j] + int(st[i][n] == st[j][n + 1]); 

        for (int i = 0; i < H; i++)
            for (int j = 0; j < H; j++)
                dp[i + 1][j + 1] = min(dp[i][j + 1], dp[i + 1][j]) + ma[i + 1][j + 1];

        ans += dp[H][H];
    }

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


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<utility>
#include<map>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;


long long int gcd(long long int a, long long int b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}




int main() {

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	long long int n, x, t;
	cin >> n >> x >> t;
	long long int p;
	if (n % x == 0)
		p = n / x;
	else {
		p = (n / x) + 1;
	}

	cout << p*t << endl;


	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define sc(m) scanf("%d",&m);
#define scl(m) scanf("%lld",&m);
#define scd(m) scanf("%lf",&m);
#define pf(res) printf("%d",res);
#define pfl(res) printf("%lld",res);
#define pfd(res) printf("%lf",res);
using namespace std;

int arr[1005];
int main()
{
    lln a,b,c,d,sum=0;
    cin>>a>>b>>c>>d;
    int p=min(a,d);
    sum+=p;
    d-=p;
    p=min(b,d);
    d-=p;
    p=min(c,d);
    sum-=p;
    cout<<sum;

}





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

const ll INF = 2E+18;

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

    ll a, accA[N+1] = {};
    for (int i=1; i<=N; i++) {
        cin >> a;
        accA[i] = a + accA[i-1];
    }

    ll ans = INF;
    for (int i=1; i<N; i++) {
        ans = min(ans, abs(accA[N] - 2 * accA[i]));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
#define rep(i, a, b) for(re int i = (a); i <= (b); ++ i)
#define drep(i, a, b) for(re int i = (b); i >= (a); -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define D double
#define inf 1023456789
#define mod 1000000007
#define lb(x) (x)&(-(x))
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define maxn 1000005
int n, m, ch[maxn][27], rt, cnt, is[1000005][27], ton[27], fa[1000005], pax, ans;
struct node {
    string c;
    int len;
}e[maxn];
il bool cmp(node a, node b) {
    return a.len > b.len;
}
il void insert(int &now, int pa, int x) {
    if(x == -1) return;
    if(!now) now = ++ cnt;
    pax = now;
    insert(ch[now][e[pa].c[x] - 'a' + 1], pa, x - 1);
    fa[ch[now][e[pa].c[x] - 'a' + 1]] = now;
}
il int find(int now, int pa, int x) {
    if(x == 0) return is[now][e[pa].c[0] - 'a' + 1];
    if(ch[now][e[pa].c[x] - 'a' + 1]) return find(ch[now][e[pa].c[x] - 'a' + 1], pa, x - 1);
    return 0;
}
signed main() {
	n = read();
    rep(i, 1, n) cin >> e[i].c, e[i].len = e[i].c.size();
    sort(e + 1, e + n + 1, cmp);
    rep(i, 1, n) {
        ans += find(rt, i, e[i].len - 1);
        insert(rt, i, e[i].len - 1);
        rep(j, 0, e[i].len - 1) {
            ton[e[i].c[j] - 'a' + 1] = 1;
            rep(k, 1, 26) is[pax][k] += ton[k];
            pax = fa[pax];
        }
        rep(i, 1, 26) ton[i] = 0;
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 300764
#include <bits/stdc++.h>
#define ll long long
#define REP(i, n) for (ll (i) = 0; (i) < (n); (i)++)
#define REPI(i, a, b) for (ll (i) = (a); (i) < (b); (i)++)
#define int long long
using namespace std;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;

const int MOD = 1000000007;
int N;
string S1, S2;
vector<bool> single;

void solve() {
  int ans = 1;
  if (single[0]) {
    ans *= 3;
  } else {
    ans *= 6;
  }

  REPI (i, 1, single.size()) {
    if (single[i]) {
      if (single[i-1]) {
        ans = ans * 2 % MOD;
      }
    } else {
      if (single[i-1]) {
        ans = ans * 2 % MOD;
      } else {
        ans = ans * 3 % MOD;
      }
    }
  }
  cout << ans << endl;
}

signed main() {
  cin >> N >> S1 >> S2;
  REP (i, N) {
    if (S1[i] == S2[i]) {
      single.push_back(true);
    } else {
      single.push_back(false);
      i++;
    }
  }
  solve();
}


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

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> can_reach_from_1;
    vector<int> can_reach_to_n;
    vector<pair<int, int>> link;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        link.emplace_back(a, b);
        if (a == 1) can_reach_from_1.push_back(b);
        if (b == n) can_reach_to_n.push_back(a);
    }

    sort(can_reach_from_1.begin(), can_reach_from_1.end());
    sort(can_reach_to_n.begin(), can_reach_to_n.end());

    bool ans = false;
    for (int i = 0; i < can_reach_from_1.size(); i++) {
        ans = binary_search(can_reach_to_n.begin(), can_reach_to_n.end(), can_reach_from_1[i]);
        if(ans) break;
    }

    cout << (ans ? "POSSIBLE" : "IMPOSSIBLE") << endl;


    return 0;
}

Measured memory_bytes: 6404
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;

int main (void){
  int count=0;
  int c_a=200001;
  int c_z=0;
  string ch;
  
  cin >> ch;
  while(ch[count] != NULL){
    if(ch[count] == 'A' && c_a == 200001)
      c_a = count;
    if(c_a != 200001 && ch[count] == 'Z')
      c_z = count;
    count++;
  }
  
  cout << c_z - c_a +1 << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>    //C++の標準ライブラリのヘッダを全て読み込む
 using namespace std;
int main() {
    

    int N;
    string s;
    int P = 0, W = 0, G = 0, Y = 0;
    cin >> N;
 
    for(int i = 0; i < N; i++)
    {
        cin >> s[i];
    }

    for(int i = 0; i < N; i++)
    {
        if(s[i] == 'P'){
            P = 1;
        } else if(s[i] == 'W'){
            W = 1;
        } else if(s[i] == 'G'){
            G = 1;
        } else if(s[i] == 'Y'){
            Y = 1;
        } 
            
        
    }

    if(P+W+G+Y > 3){
        cout << "Four" << endl;
    } else {
        cout << "Three" << endl;
    }


}


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

int main() {
  int n; string s;
  cin >> n >> s;
  int ans=s.size();
  rep(i,n){
    if(s[i]==s[i+1]) ans--;
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b;a<=c;++a)
#define Dor(a,b,c) for(int a=b;a>=c;--a)
using namespace std;
typedef long long LL;
LL n,a,b,c,d,w;
map<LL,LL> F;
void eat(LL u,LL f) {
	if(u>=w) return;
	LL g=F[u];
	if(!g||f<g) F[u]=f;
}
void magic() {
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	F.clear();
	LL h=0,t=1,ans=1LL<<60; F[n]=0;
	while(h<t) {
		LL x=F.rbegin()->first,f=F.rbegin()->second;
		w=x;
		if(1.*x*d<1e18) ans=min(ans,x*d+f);
		if(x==0) break;
		F.erase(--F.end());
		eat(x/2,a+(x%2)*d+f);
		eat(x/3,b+(x%3)*d+f);
		eat(x/5,c+(x%5)*d+f);
		eat((x+1)/2,a+(2-x%2)*d+f);
		eat((x+2)/3,b+(3-x%3)*d+f);
		eat((x+4)/5,c+(5-x%5)*d+f);
	}
	printf("%lld\n",ans);
}
int main() {
	int T;
	scanf("%d",&T);
	while(T--) magic();
	return 0;
}

Measured memory_bytes: 3848
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(long long (i)=0;(i)<(n);++(i))
#define ref(i,a,b) for (long long (i)=(a); (i)<=(b); ++(i))
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define mp make_pair
const int mx=1e6+105;
bool pr[2*mx];
vector <long long > p;
long long gcd(long long a, long long b) {
	while(b!=0){
		a%=b;
		swap(a,b);
	}
	return a;
}
int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	ll a,b;cin >> a >> b;
	ll res=gcd(a,b);
	ll ans=1;
	for(ll i=2;i*i<=res;++i){
		if(res%i==0)++ans;
		while(res%i==0)res/=i;
	}
	if(res!=1)++ans;
	cout << ans << endl;
}


Measured memory_bytes: 256
import math
n, d= (int(c) for c in input().split())

x = []

for i in range(n): 
    x.append(input().split())

sum_ans = 0
count=0
print
for j in range(0,n-1):
    for k in range(j+1,n):
        for l in range(d):
            sum_ans = sum_ans+(int(x[j][l]) - int(x[k][l])) **2
        if math.sqrt(sum_ans)%1==0.0:
            count=count+1
        sum_ans=0
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int n;
float arrlen[1000000],arr[100000];
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%f",&arr[i]);
	}
	sort(arr,arr+n);
	double da=0;
	for(int i=0;i<n;i++){
		if(arr[n]!=arr[i]){
			da+=arr[n-1]/arr[i];
		}else{
			da++;
		}
	}
	da=arr[n-1]/da;
	printf("%f",da);
	return 0;
}

Measured memory_bytes: 2432
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <list>
#include <cmath>
#include <stack>

using namespace std;
typedef long long ll;
using Pll = pair<ll,ll>;

int main() {
    ll K;
    cin >> K;
    vector<ll> res(50);
    if(K<50){
        if(K==0){
            cout << 2 << endl;
            cout << 0 << " " << 0 << endl;
            return 0;
        }
        else if(K==1){
            cout << 3 << endl;
            cout << 1 << " " << 0 << " " << 3 << endl;
            return 0;
        }
        cout << K << endl;
        for(int i=0;i<K;i++){
            cout << K;
            if(i!=K-1) cout << " ";
        }
        cout << endl;
        return 0;
    }
    else{
        for(int i=0;i<50;i++){
            res[i]=50-i;
        }
        ll tmp=K%50;
        for(int i=0;i<50;i++){
            res[i]+=(K-50)/50;
            if(tmp){
                res[i]+=1;
                tmp--;
            }
        }
    }
    cout << 50 << endl;
    for(int i=0;i<50;i++){
        cout << res[i];
        if(i!=49)cout << " ";
    }
    cout << endl;

    return 0;
}

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

int main() {
  int x, y;
  cin >> x >> y;
  int ans =0;
  
  if(x==1) ans += 300000;
  if(y==1) ans += 300000;
  if(x==1 && y==1) ans += 400000;
  if(x==2) ans += 200000;
  if(y==2) ans += 200000;
  if(x==3) ans += 100000;
  if(y==3) ans += 100000;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int maxn=1e5+100;
int A,B,M;
int a[maxn],b[maxn],x[maxn],y[maxn],c[maxn],e[maxn],d[maxn];
int main()
{
    scanf("%d%d%d",&A,&B,&M);
    for(int i=1;i<=A;i++){
        scanf("%d",&a[i]);
        e[i]=a[i];
    }
    for(int i=1;i<=B;i++){
        scanf("%d",&b[i]);
        d[i]=b[i];
    }
    sort(e+1,e+1+A);
    sort(d+1,d+1+B);
    int sum=e[1]+d[1];
    for(int i=1;i<=M;i++){
        scanf("%d%d%d",&x[i],&y[i],&c[i]);
        int tmp=a[x[i]]+b[y[i]]-c[i];
        sum=min(tmp,sum);
    }
    printf("%d\n",sum);
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> DP(N + 1, N);
  DP.at(0) = 0;

  for (int i = 0; i < N; i++) {
    for (int j = 1; i + j <= N; j *= 6) {
      DP.at(i + j) = min(DP.at(i + j), DP.at(i) + 1);
    }
    for (int j = 1; i + j <= N; j *= 9) {
      DP.at(i + j) = min(DP.at(i + j), DP.at(i) + 1);
    }
  }

  cout << DP.at(N) << "\n";
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

typedef long long ll;


const int MAX = 700000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll x, y;    cin >> x >> y;

    ll a = 2*x-y, b = 2*y-x;

    if (b%3 != 0 || a%3 != 0 || a < 0 || b < 0) {
        cout << 0 << endl;
        return 0;
    }

    a = a / 3;
    b = b / 3;

    COMinit();

    ll ans = COM(a+b, a);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 16768
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int 
const int MOD = 1e9+7;
const int MAXN = 2e5+5;
 
int32_t main()
{
   
    IOS
    int n,d;
    cin>>n>>d;
    int ans=ceil((1.0*n)/(2*d+1));
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
typedef long long ll;
using namespace std;
#define mul(a, b) (((i64)(a) * (b) ) % MOD)
#define sum(a, b) (((a) + (b) ) % MOD)

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

	#define endl '\n'

	#ifdef LOCAL_DEBUG
		freopen("data.in", "r", stdin );
	#endif
	int n; cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; i++)cin >> a[i];
	ll s = 0;
	map<ll, int> M;
	M[0] = 1;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		s += a[i];
		if(M.count(s) > 0){
			ans += M[s];
		}
		M[s] += 1;
	}
	cout << ans << endl;



}


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

int main()
{
  string s;

  cin >> s;

  int sum = 0;

  for(const auto c : s){
    sum += atoi(&c);
  }

  if(sum%9 == 0){
    cout << "Yes\n";
  }
  else{
    cout << "No\n";
  }

  return 0;
}

Measured memory_bytes: 3752
import java.util.Scanner;

/**
 * Created by zzt on 17-1-29.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        long ret = (x/11)*2;
        long mod = x % 11;
        if (mod!=0)
            ret++;
        if (mod>6)
            ret++;
        System.out.println(ret);
    }
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

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

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

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

    vector<int> A(N);
    for (auto &i : A) cin >> i;
    sort(A.begin(), A.end(), greater<int>());

    auto f = [&](double x){
        int count = 0;
        for (auto &i : A) count += ceil(i/x) - 1;
        return count <= K;
    };

    double l = 0.0, r = 1e9;
    rep(i, 100) {
        double mid = (l + r) / 2.0;
        if (f(mid)) r = mid;
        else l = mid;
    }

    printf("%d\n", (int)ceil(l));
}

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

template<typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}

template<int mod>
struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long x_) { if ((x = x_ % mod + mod) >= mod) x -= mod; }
    ModInt& operator+=(ModInt rhs) { if ((x += rhs.x) >= mod) x -= mod; return *this; }
    ModInt& operator-=(ModInt rhs) { if ((x -= rhs.x) < 0) x += mod; return *this; }
    ModInt& operator*=(ModInt rhs) { x = (unsigned long long) x * rhs.x % mod; return *this; }
    ModInt& operator/=(ModInt rhs) { x = (unsigned long long) x * rhs.inv().x % mod; return *this; }

    ModInt operator-() const { return -x < 0 ? mod - x : -x; }
    ModInt operator+(ModInt rhs) const { return ModInt(*this) += rhs; }
    ModInt operator-(ModInt rhs) const { return ModInt(*this) -= rhs; }
    ModInt operator*(ModInt rhs) const { return ModInt(*this) *= rhs; }
    ModInt operator/(ModInt rhs) const { return ModInt(*this) /= rhs; }
    bool operator==(ModInt rhs) const { return x == rhs.x; }
    bool operator!=(ModInt rhs) const { return x != rhs.x; }
    ModInt inv() const { return pow(*this, mod - 2); }

    friend ostream& operator<<(ostream& s, ModInt<mod> a) { s << a.x; return s; }
    friend istream& operator>>(istream& s, ModInt<mod>& a) { s >> a.x; return s; }
};

using mint = ModInt<1000000007>;
mint dp[2020][2020];
mint dsum[2020][2020];

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

    int n, m;
    cin >> n >> m;
    dp[0][0] = dsum[0][0] = 1;
    for (int i = 1; i <= n; i++) dsum[i][0] = 1;
    for (int i = 1; i <= m; i++) dsum[0][i] = 1;
    vector<int> as(n), bs(m);
    for (int i = 0; i < n; i++) cin >> as[i];
    for (int i = 0; i < m; i++) cin >> bs[i];

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (as[i] != bs[j]) {
                dp[i + 1][j + 1] = 0;
                dsum[i + 1][j + 1] = dsum[i][j + 1] + dsum[i + 1][j] - dsum[i][j] + dp[i + 1][j + 1];
            } else {
                dp[i + 1][j + 1] = dsum[i][j];
                dsum[i + 1][j + 1] = dsum[i][j + 1] + dsum[i + 1][j] - dsum[i][j] + dp[i + 1][j + 1];
            }
        }
    }
    cout << dsum[n][m] << endl;
}

Measured memory_bytes: 32128
#pragma GCC optimize ("O2")
#pragma GCC target ("avx2")
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please


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


	int H, W;
	cin >> H >> W;
	int CH, CW, DH, DW;
	cin >> CH >> CW >> DH >> DW;
	CH--;
	CW--;
	DH--;
	DW--;

	int C[1000000];
	ll D[1000000];

	rep(i, H * W) {
		D[i] = 1e18;
	}
	rep(i, H) {
		string S;
		cin >> S;
		rep(j, W) {
			if (S[j] == '#') C[i * W + j] = -1;
			else C[i * W + j] = 0;
		}
	}

#define PT pair<ll, int>
	priority_queue<PT, vector<PT>, greater<PT>> q;

	auto CHK = [&](int h, int w, ll d) {
		if (h >= 0 && h < H && w >= 0 && w < W) {
			int t = h * W + w;
			if (C[t] != -1 && D[t] > d) {
				D[t] = d;
				q.push({ d, t });
			}
		}
	};

	int st = CH * W + CW;
	int gl = DH * W + DW;

	D[st] = 0;
	q.push({ 0, st });
	while (q.size()) {
		PT p = q.top();
		q.pop();
		int f = p.second;
		if (D[f] != p.first) continue;

		int h = f / W;
		int w = f % W;

		CHK(h - 1, w, D[f]);
		CHK(h + 1, w, D[f]);
		CHK(h, w - 1, D[f]);
		CHK(h, w + 1, D[f]);
		for (int x = -2; x <= 2; x++) {
			for (int y = -2; y <= 2; y++) {
				CHK(h + x, w + y, D[f] + 1);
			}
		}
	}

	ll kotae = D[gl];
	if (kotae > 1e11) co(-1);
	else co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 15536
n, m = map(int, input().split())
mod = 10**9+7

fact = [1]
for i in range(1, max(n, m) + 1):
    fact.append(fact[-1] * i % mod)

if abs(n - m) >= 2:
    print(0)
elif abs(n - m) == 1:
    print(fact[n] * fact[m] % mod)
elif abs(n - m) == 0:
    print(2 * fact[n] * fact[m] % mod)


Measured memory_bytes: 12936
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) throws Exception {
		while (true) {
			int N = sc.nextInt();
			if (N == 0) break;
			int Q = sc.nextInt();
			int[] day = new int[100];
			for (int i = 0; i < N; ++i) {
				int M = sc.nextInt();
				for (int j = 0; j < M; ++j) {
					day[sc.nextInt()]++;
				}
			}
			int max = 0;
			int ans = 0;
			for (int i = 0; i < 100; ++i) {
				if (day[i] > max) {
					max = day[i];
					ans = i;
				}
			}
			System.out.println(max < Q ? 0 : ans);
		}
	}

}

Measured memory_bytes: 62544
#include<stdio.h>
#include<math.h>
#include<string.h>
#define ll long long int


void sort(int a[],ll n){

ll i,j,temp;

for(i=0;i<n;i++){

    for(j=0;j<n;j++){

        if(a[i]<a[j]){
            temp=a[i];
            a[i]=a[j];
            a[j]=temp;
        }
    }

}



}


int main(){



int n,i;
char a[100];
char b[100];

scanf("%lld",&n);
scanf("%s",a);
scanf("%s",b);

for(i=0;i<n;i++)
{

    printf("%c%c",a[i],b[i]);



}






return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef pair<ii,ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1LL<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1LL<<(i))))
#define setbit1(n,i) ((n)|(1LL<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define DBG(a) cout<<#a<<" ->->->-> "<<a<<endl
#define EN cout<<"\n"
#define fi first
#define se second
#define PI (acos(-1))
#define fastread ios::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 1000005
template<class T> ostream& operator<<(ostream &s,pair<T,ll> a)
{
    s<<a.fi<<' '<<a.se;
    return s;
}
int main()
{
    fastread;
    ll T=1;
//    cin>>T;
    for(ll qq=1;qq<=T;qq++)
    {
        ll n;
        cin>>n;
        ll ans=INF;
        vi v(n);
        for(auto &x:v)cin>>x;
        for(int i=1;i<=100;i++)
        {
            ll a=0;
            for(auto x:v)a+=(i-x)*(i-x);
            ans=min(ans,a);
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 256