akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
int dp[2010][2010] = {0};
int sm[2010][2010] = {0};
signed main(){
    
    int n,m;
    cin >> n >> m;
    vector<int> s(n);
    vector<int> t(m);

    rep(i,n)cin >> s[i];
    rep(i,m)cin >> t[i];

    rep(i,2005)dp[i][0] = dp[0][i] = 1;
    
    for(int i = 1;i <= n;i++){
        for(int j = 1;j <= m;j++){
            if(s[i-1] == t[j-1]){
                dp[i][j] = (dp[i][j-1] + dp[i-1][j])%MOD;
            }else{
                dp[i][j] = (dp[i][j-1] + dp[i-1][j] - dp[i-1][j-1]+MOD)%MOD;
            }
        }
    }

    // for(int i = 1;i <= n;i++){
    //     for(int j = 1;j <= m;j++){
    //         if(s[i-1] == t[j-1]){
    //             dp[i][j] = (dp[i-1][j] + dp[i][j-1] + 1)%MOD;
    //         }else{
    //             dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]+MOD)%MOD;
    //         }
    //     }
    // }
    cout << dp[n][m]%MOD << endl;

    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc130.contest.atcoder.jp/tasks/abc130_b


Measured memory_bytes: 32512
// finish date: 2018/01/22
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N;
    ll K;
    cin >> N >> K;
    map<int, ll> mp;
    int a, b;
    rep(i, N) {
        cin >> a >> b;
        mp[a] += b;
    }
    ll sum = 0;
    for(auto itr:mp){
        sum+=itr.second;
        if(sum>=K){
            cout<<itr.first<<endl;
            return 0;
        }
    }

    return 0;
}



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

int main(){
   int n,d,x;cin>>n>>d>>x;
   int ans=0;
   while(n--){
       int a;cin>>a;
       int b=1;
       while(b<=d){
           ans++;
           b+=a;
       }
   }
   cout<<ans+x;
}

Measured memory_bytes: 256
import math
from functools import reduce
import itertools
import numpy as np

K = int(input())

l = list(range(1,K+1))

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

c = list(itertools.combinations_with_replacement(l,3))
sm = 0
for a in c:
    if a[0] == a[1] == a[2]:
        sm += gcd_list(list(a))
    elif a[0] != a[1] != a[2]:
        sm += gcd_list(list(a)) * 3 * 2
    else:
        sm += gcd_list(list(a)) * 3

print(sm)

Measured memory_bytes: 123436
#include<iostream>
using namespace std;
 
int main(){
  int A,B;
  scanf("%d",&A);
  scanf("%d",&B);
  int res;
  res = (2*A-1>2*B-1)?2*A-1:2*B-1;
  res = (res>A+B)?res:A+B;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string s;
  cin>>s;
  if(s=="abc"||s=="acb"||s=="bac"||s=="bca"||s=="cab"||s=="cba"){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}

Measured memory_bytes: 3624
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
 
const int inf = 999999999;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define ret return
 
ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
 
///////////////////////////////////////////////////////////////////////////
 
ll n,a,b,h[100005] = {};
 
bool boon(ll k){
    ll t[100005] = {};
    ll kk  = k;
    rep(i,0,n){
        t[i] = h[i];
        t[i] -= b*k;
        if(t[i] > 0){
            kk -= (t[i]+(a-b)-1)/(a-b);
            if(kk < 0)return false;
        }
    }
    return true;
}
 
int main(){
	cin >> n >> a >> b;
    rep(i,0,n)cin >> h[i];
    sort(h,h+n);
    ll l = 1,r = (h[n-1]+b-1)/b;
    ll k;
    
    //r = 1000000002;
    while(l < r){
        k = (l+r)/2;
 
        if(boon(k)) r = k;
        else l = k+1;
    }
    k = (l+r)/2;
 
    if(boon(k))cout << k << endl;
    else cout << k-1 << endl;
	return  0;
}

Measured memory_bytes: 1024
#define D(x) cout << #x " = " << x << endl
#define DD(x, y) cout << "(" #x ", " #y ") = (" << x << ", " << y << ")" << endl
#define DDD(x, y, z) cout << "(" #x ", " #y ", " #z ") = (" << x << ", " << y << ", " << z << ")" << endl
#define DV(v) for (auto __macro_vi : v){ cout << __macro_vi << " ";} cout << endl;
#define DA(a, n) for (int __macro_i = 0; __macro_i < n; ++__macro_i) { cout << a[__macro_i] << " "; } cout << endl;
#define REP(i, n) for (int i = 0; i < n; ++i)
#define ALL(v) (v).begin(), (v).end()
#include<iostream>
#include<vector>
#include<cassert>
#include<cmath>
#include<iomanip>

using namespace std;

vector<vector<double>> dp;
vector<double> p;
int n;
int main()
{
    cin >> n;
    p.resize(n);
    dp = vector<vector<double>>(n + 1, vector<double>(n + 1, -1));
    REP(i, n) cin >> p[i];
    REP(i, n + 1) {
        dp[0][i] = 0;
    }
    dp[0][0] = 1;
    
    for (int i = 1; i <= n; ++i) {
        double pi = p[i - 1];
        // D(pi);
        REP(j, n + 1) {
            double tmp = 0;
            if (j > 0) tmp += dp[i - 1][j - 1] * pi;
            if (i >= j) tmp += dp[i - 1][j] * (1 - pi);
            dp[i][j] = tmp;
        }
    }
    double ans =0;
    for (int i = n / 2 + 1; i < n + 1; ++i) {
        ans += dp[n][i];
    }
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 70784
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long 
using namespace std;

signed main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	for(int i = 0;i < N;i++) {
		cin >> A.at(i);
	}
	for(int i = 0;i < N;i++) {
		cin >> B.at(i);
	}
	int answer = 0;
	for(int i = 0;i < N;i++) {
		int count = 0;
		for(int j = 0;j <= i;j++) {
			count += A.at(j);
		}
		for(int j = i;j < N;j++) {
			count += B.at(j);
		}
		answer = max(answer,count);
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
N,K = input().split()

N = int(N)
K = int(K)

h_list = []
for i in range(N):
    h_list.append(int(input()))

h_list = sorted(h_list)

hmin = max(h_list)
for i in range(N-K+1):
    h_s = h_list[i]
    h_b = h_list[i+K-1]
    if h_b - h_s < hmin:
        hmin = h_b - h_s

print(hmin)

Measured memory_bytes: 8280
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))
#define PRECISION(x) std::fixed << std::setprecision(x)

using namespace std;

using ll = long long;
using VI = std::vector<int>;
using VI2D = std::vector<vector<int>>;
using VLL = std::vector<long long>;
using VLL2D = std::vector<vector<long long>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

// "(B (BP (P) PB) P (BP (P) PB) B) P (B (BP (P) PB) P (BP (P) PB) B)"

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

	VLL patty_count(52, 1);
	VLL layer_count(52, 1);
	REP(i, n + 1) {
		patty_count[i + 1] = patty_count[i] * 2 + 1;
		layer_count[i + 1] = layer_count[i] * 2 + 3;
	}

	ll result = 0;
	x++;
	for(int i = n; i >= 0; i--) {
		if(layer_count[i] + 2 <= x) {
			result += patty_count[i] + 1;
			x -= layer_count[i] + 2;
			if(layer_count[i] == x) {
				result += patty_count[i];
				x -= layer_count[i];
			}
		} else if(layer_count[i] + 1 == x) {
			result += patty_count[i];
			x -= layer_count[i] + 1;
		} else {
			x--;
		}
	}

	cout << result << endl;

	return 0;
}


Measured memory_bytes: 3632
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define YY cout << "Yes" << endl;
#define NN cout << "No" << endl;
#define ve vector
#define pint pair<int,int>
const int INF = 1000000007;
const long double EPS = 1e-15;
const long double PI = acos(-1);
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
// *max_element(all(d))
// priority_queue<int,vector<int>,greater<int>>
int solve(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 0;
  REP(i,1,n){
    string a = s.substr(0,i),b = s.substr(i,n - i);
    map<char,int>cnt;
    rep(j,a.size())if(cnt[a[j]] == 0)cnt[a[j]]++;
    rep(j,b.size())if(cnt[b[j]] == 1)cnt[b[j]]++;
    int tmp = 0;
    for(auto j : cnt)if(j.second > 1)tmp++;
    ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0; 
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  cout << fixed;cout << setprecision(16);
  solve();
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int a,b,k;
  cin>>a>>b>>k;
  if(k==0)
  {
      cout<<a<<" "<<b;
  }
  else if(a+b<=k)
  {
      cout<<0<<" "<<0;
  }
  else if(a<=k && a+b>=k)
  {
          cout<<0<<" "<<abs(k-a-b);
  }
  else if(a>=k)
  {
      cout<<abs(a-k)<<" "<<b;
  }

  return 0;


}


Measured memory_bytes: 3596
def main():
    n = int(input())
    hlis = list(map(int, input().split()))

    for i in range(0, n-1):
        if hlis[i]-1 > hlis[i+1]:
            print("No")
            exit()
        elif hlis[i]-1 == hlis[i+1]:
            hlis[i] = hlis[i] - 1
            if i > 1 and hlis[i-1] > hlis[i]:
                print('No')
                exit()
        elif i > 1 and hlis[i-1] <= hlis[i] - 1:
            hlis[i] = hlis[i]-1
    print("Yes")

if __name__ == "__main__":
    main()


Measured memory_bytes: 85396
#include<cstdio>
#include<cstring>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=100005;
const LL Mod=998244353;
struct S
{
    int a,b;
}s[N];
bool cmp(S x, S y)
{
    if(x.a==y.a)
        return x.b>y.b;
    return x.a<y.a;
}
vector<vector<int> > w(N);
int main()
{
    int n,m,k[N];
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        for(int i=0;i<=n;i++)
            w[i].clear();
        for(int i=0;i<m;i++)
        {
            scanf("%d%d",&s[i].a,&s[i].b);
        }
        sort(s,s+m,cmp);
        for(int i=0;i<m;i++)
        {
            w[s[i].b].push_back(s[i].a);
        }
        double last=0.0;
        int ans=0;
        for(int i=1;i<=n;i++)
        {
            if(w[i].size()>0)
            {
                int latestA=max(w[i][0],w[i][w[i].size()-1]);
                if(latestA>last)
                {
                    last=i-0.5;
                    ans++;
                }
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
int K;
string S;
vi va, vb;

void input() {
  ;
  cin >> K;
  ;
}
int rn[MX * 10];

// int isrn(int x) {
//   int prev = x % 10;
//   x /= 10;
//   bool ret = true;
//   while (x) {
//     if (abs(prev - (x % 10)) <= 1) {
//       x /= 10;
//     } else {
//       ret = false;
//       break;
//     }
//   }
//   cout << ret;
// }

int cntketa[12];
int num = 1;

void dfs(int now, int depth, int mdepth) {
  if (depth == mdepth) {
    // cout << now << endl;
    rn[num] = now;
    num++;
    return;
  }

  depth++;
  if (now % 10 == 0) {
    dfs(now * 10, depth, mdepth);
    dfs(now * 10 + 1, depth, mdepth);
  } else if (now % 10 == 9) {
    dfs(now * 10 + 8, depth, mdepth);
    dfs(now * 10 + 9, depth, mdepth);
  } else {
    int k = now % 10;
    dfs(now * 10 + k - 1, depth, mdepth);
    dfs(now * 10 + k, depth, mdepth);
    dfs(now * 10 + k + 1, depth, mdepth);
  }
}
void solve() {
  // //  zenburekkyo
  // rn[1] = 1;
  // rn[2] = 2;
  // rep(i, 3, 9) rn[i] = i;
  // rn[10] = 10;
  // rn[11] = 11;
  // rn[12] = 12;
  // rn[13] = 21;
  // rn[14] = 22;
  // rn[15] = 23;
  // rn[16] = 32;
  // rn[17] = 33;
  // rn[18] = 34;
  // rn[19] = 43;

  // cntketa[1] = 9;
  // cntketa[2] = 3 * 8 + 2;  // 9 -> 2, else -> 3

  rep(keta, 1, 11){             // cout << "keta=" << keta << endl;
                   rep(i, 1, 9){// cout << dfs(i, 1, keta) << endl;
                                dfs(i, 1, keta);
  ;
}
}
;

// rep(i, 1, 50) { debug2(i, rn[i]); };
// debug(rn[100000]);
cout << rn[K] << endl;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

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

#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s = "ACL";
  ll n;
  cin >> n;
  REP(i, n) { cout << s; }
  cout << endl;
}

Measured memory_bytes: 3632
n=int(input())
l=list(map(int,input().split()))
ans = 0
l.sort()
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i] == l[j] or l[j] == l[k]:continue
            if l[i]+l[j] > l[k]:
                ans += 1
print(ans)

Measured memory_bytes: 73484
#include <iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(void){
    int n,i;
    string s,ans="Yes";
    cin>>n>>s;
    if(n%2==1)ans="No";
    for(i=0;i<n/2;i++){
        if(s[i]!=s[i+n/2])ans="No";
    }
    cout<<ans;
}


Measured memory_bytes: 256
dbflag=""

def debug(*args):
  if ""!=dbflag: print(*args)

if ""!=dbflag: _INDATA=open(dbflag)

def readline():
  if ""!=dbflag:return _INDATA.readline()
  else: return input()


result = 0

A = int(readline())
B = int(readline())
C = int(readline())
X = int(readline())



for a in range(A+1):
	for b in range(B+1):
		for c in range(C+1):
			if 500*a + 100*b + 50 * c == X:
				result += 1

print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i, n)for(int i=0; i<n; i++)

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

  long long dig_sum = 0;

  rep(i, N.size() ){
    dig_sum += N[i]-'0';
  }

  if(dig_sum%9 == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 3716
from collections import Counter

def resolve():
    n = int(input())
    a = list(map(int, input().split()))
    acc = sum(a)
    counter = Counter(a)
    q = int(input())
    for _ in range(q):
        b, c = map(int, input().split())
        if b in counter:
            if c not in counter:
                counter[c] = 0
            acc += counter[b] * c - counter[b] * b
            counter[c] += counter[b]
            counter[b] = 0
        print(acc)

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 21288
#include <bits/stdc++.h>
using namespace std;
const int N = 33;

int n, m;
int q[N];

int main()
{
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
    {
        int k;
        cin >> k;
        while (k--)
        {
            int x;
            cin >> x;
            q[x]++;
        }
    }
    int ans = 0;
    for (int i = 1; i <= m; ++i)
    {
        if (q[i] == n)
            ++ans;
    }
    cout << ans << endl;
    return 0;
}


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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"
*/

int main()
{
    int N;
    cin >> N;
    ll sum = 0;
    for(int i=1; i<=N; i++){
        if(i % 3 == 0 || i % 5 == 0) continue;
        else sum += i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define rep(i,n) for(int i=0; i<n; i++)
typedef long long ll;
typedef pair<int,int> P;
const ll MOD = (int)1e9+7;
const ll INF = MOD*MOD;
const ll powll = 1LL<<1;

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

  int m[h][w];
  rep(i,h) rep(j,w) m[i][j] = MOD;
  
  if(s[0][0] == '#') m[0][0] = 1;
  else m[0][0] = 0;

  rep(i,h){
    rep(j,w){
      if(i == 0 && j == 0) continue;
      else if(i == 0){
        if(s[0][j] == '#' && s[0][j-1] == '.') 
          m[0][j] = m[0][j-1] + 1;
        else
          m[0][j] = m[0][j-1];
      }else if(j == 0){
        if(s[i][0] == '#' && s[i-1][0] == '.')
          m[i][0] = m[i-1][0] + 1;
        else
          m[i][0] = m[i-1][0];
      }else{
        int dw = 0, le = 0;
        if(s[i-1][j] == '.') dw = 1;
        if(s[i][j-1] == '.') le = 1;
        
        if(s[i][j] == '#')
          m[i][j] = min(m[i-1][j]+dw, m[i][j-1]+le);
        else
          m[i][j] = min(m[i-1][j], m[i][j-1]);
      }
    }
  }
  cout << m[h-1][w-1] << "\n";
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include<iomanip>

using namespace std;

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

typedef long long ll;

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; }

void fail()
{
	cout << -1 << endl;
}

void Main()
{
	int M, K; cin >> M >> K;
	if (pow(2, M) <= K) {
		fail();
		return;
	}
	if (M == 0) {
		if (K == 0) {
			cout << "0 0" << endl;
			return;
		} else {
			fail();
			return;
		}
	}
	if (M == 1) {
		if (K == 0) {
			cout << "0 0 1 1" << endl;
			return;
		} else {
			fail();
			return;
		}
	}
	int p = pow(2,M);
	rep(i,p) {
		if (i == K) continue;
		cout << i << " ";
	}
	cout << K << " ";
	rep(i,p) {
		if ((p - i - 1) == K) continue;
		cout << (p - i - 1) << " ";
	}
	cout << K << endl;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
inline int Read(){
	int x=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int main(){
	int a,b,c;
	a=Read();b=Read();c=Read();
	if(a==b)printf("%d\n",c);
	else{
		if(a==c)printf("%d\n",b);
		else printf("%d\n",a);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<(n);i++)
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=100005;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n,m;
      cin>>n>>m;
      vector<int> a[m];
      for(int i=0;i<m;i++)
      {
            int k;
            cin>>k;
            for(int j=0;j<k;j++)
            {
                  int x;
                  cin>>x;
                  x--;
                  a[i].pb(x);
            }
      }
      // return 0;
      int p[m];
      for(int i=0;i<m;i++) cin>>p[i];
      int ans=0;
      for(int i=0;i<(1LL<<n);i++)
      {
            map<int,int> ma;
            for(int j=0;j<n;j++)
            {
                  if((i>>j)&1) ma[j]++;
                  //cout<<((i>>j)&1)<<" ";
            }
            // cout<<"\n";
            bool f=true;
            for(int j=0;j<m;j++)
            {
                  int cnt=0;
                  for(auto x: a[j])
                  {
                        if(ma[x]) cnt++;
                  }
                  if(cnt%2!=p[j]){
                        f=false;
                  } 
            }
            if(f) ans++;
      }
      cout<<ans;
}     


Measured memory_bytes: 256
n = int(input())
numbers = list(map(lambda x: int(x), input().split()))

sum_n = sum(numbers)
total_value = 0

for current_num in numbers:
    sum_n -= current_num
    total_value += current_num * sum_n
#     print(sum_n, total_value, current_num)

print(total_value % (10**9+7))

Measured memory_bytes: 31680
# coding: utf-8
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

MOD = 10 ** 9 + 7
# K回の移動が終わった後、人がいる部屋の数はNからN-K

def cmb(n, k):
    if k < 0 or k > n: return 0
    return fact[n] * fact_inv[k] % MOD * fact_inv[n-k] % MOD

def cumprod(arr, MOD):
    L = len(arr); Lsq = int(L**.5+1)
    arr = np.resize(arr, Lsq**2).reshape(Lsq, Lsq)
    for n in range(1, Lsq):
        arr[:, n] *= arr[:, n-1]; arr[:, n] %= MOD
    for n in range(1, Lsq):
        arr[n] *= arr[n-1, -1]; arr[n] %= MOD
    return arr.ravel()[:L]

def make_fact(U, MOD):
    x = np.arange(U, dtype=np.int64); x[0] = 1
    fact = cumprod(x, MOD)
    x = np.arange(U, 0, -1, dtype=np.int64); x[0] = pow(int(fact[-1]), MOD-2, MOD)
    fact_inv = cumprod(x, MOD)[::-1]
    return fact, fact_inv

U = 10 ** 6  # 階乗テーブルの上限
fact, fact_inv = make_fact(U, MOD)

N, K = lr()
answer = 0
for x in range(N, max(0, N-K-1), -1):
    # x個の家には1人以上いるのでこの人たちは除く
    can_move = N - x
    # x-1の壁をcan_move+1の場所に入れる
    answer += cmb(N, x) * cmb(x - 1 + can_move, can_move)
    answer %= MOD
    
print(answer % MOD)
# 31

Measured memory_bytes: 51524
import math

# input
H, W = map(int, input().split())

# 同じ方向に三等分
ans0 = (W % 3 != 0) * H
ans1 = W * (H % 3 != 0)

blue_H = math.floor(H / 2)
i = math.floor((W * blue_H) / (H + blue_H))
ans2 = math.ceil(H / 2) * (W - i) - H * i

red_H = math.ceil(H / 2)
i = math.ceil((W * red_H) / (H + red_H))
ans3 = H * i - math.floor(H / 2) * (W - i)

blue_W = math.floor(W / 2)
i = math.floor((H * blue_W) / (W + blue_W))
ans4 = math.ceil(W / 2) * (H - i) - W * i

red_W = math.ceil(W / 2)
i = math.ceil((H * red_W) / (W + red_W))
ans5 = W * i - math.floor(W / 2) * (H - i)

ans = min(ans0, ans1, ans2, ans3, ans4, ans5)

print(ans)





Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll f(ll a,ll b){return (a <= b ? b-a : a-b+2);}
int main(){
    ll x,y;
    cin >> x >> y;
    cout << min({f(x,y),f(-x,y)+1,f(x,-y)+1}) << endl;
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;

lli n;
lli a[e5];
lli normal_cost = 0;

int main(){
	cin >> n;
	for(lli i = 1;i <= n;i++) cin >> a[i];
	for(lli i = 1;i <= n+1;i++){
		normal_cost += abs(a[i]-a[i-1]);
	}
	cerr << normal_cost << endl;
	for(lli i = 1;i <= n;i++){
		cout << normal_cost-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i+1]-a[i-1]) << endl;
	}

}


Measured memory_bytes: 2048
#include<stdio.h>
#include<stdlib.h>

int partition(int*,int,int);

int main(){
  
  int i,n;
  int A[100000];
  
  scanf("%d",&n);
  
  for(i=0; i<n; i++)
    scanf("%d",&A[i]);
  
  int Y;
  Y = partition(A, 0, n-1);
  
  /*i = A[Y];
  A[Y] = A[n-1];
  A[n-1] = i;*/
 
  for(i=0; i<n-1; i++){
    if(i==Y) printf("[%d] ",A[i]);
    else printf("%d ",A[i]);
  }
  printf("%d",A[n-1]);
  printf("\n");
  
  return 0;
}


int partition(int *A,int p,int r){
  int x=A[r];
  int i = p-1;
  int y=0;
  int j;
  for(j=p; j<=r-1; j++){
    if(A[j] <= x){ 
      i=i+1;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }}
   y = A[i+1];
    A[i+1] = A[r];
    A[r] = y;

 
  
  return i+1;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define preturn(X) cout<<X<<endl; return 0
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//cout.setf(ios::fixed); cout.precision(18)

int n;
int a[10];

int ans = 0;

void func(int x,int y){
    if(x==n){
        ans+=y;
        return;
    }
    if(a[x]%2==0){
        func(x+1,1);
        func(x+1,y);
        func(x+1,y);
    }
    else{
        func(x+1,y);
        func(x+1,1);
        func(x+1,1);
    }
}

int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    cin>>n;
    rep(i,0,n){
        cin>>a[i];
    }
    func(0,0);
    preturn(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <atcoder/all>
#define ll long long int
#define MOD 1000000007
#define P pair<ll,ll>
#define INF 1000000000000000000
#define N 100001

//using namespace atcoder;
using namespace std;
ll q, k;
ll dist[N];
vector<vector<P>> edge;

void make_dist(int cur){
  for (auto p : edge[cur]){
    ll u = p.first;
    ll d = p.second;

    if (dist[u] == -1){
      dist[u] = dist[cur] + d;
      make_dist(u);
    }
  }
  return;
}


int main(void){
  ll n;
  cin >> n;

  for (int i = 0; i < n; i++){
    dist[i] = -1;
  }

  edge = vector<vector<P>>(n, vector<P>(0));
  
  for (int i = 0; i < n-1; i++){
    ll a, b, c;
    cin >> a >> b >> c;
    a--;b--;
    
    edge[a].emplace_back(P(b, c));
    edge[b].emplace_back(P(a, c));
  }
  cin >> q >> k;

  k--;
  dist[k] = 0;
  make_dist(k);
  
  for (int i = 0; i < q; i++){
    ll x, y;
    cin >> x >> y;
    x--; y--;
    
    cout << dist[x] + dist[y] << endl;
  }


  return 0;
}


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

int main()
{
	int n, buffer, ans[2] = {0,0};
	deque<int> w;
	deque<int>::iterator p;
	
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> buffer;
		w.push_back(buffer);
	}
	while (!w.empty())
	{
		if (ans[0] <= ans[1])
		{
			ans[0] += w.front();
			w.pop_front();
		}
		else
		{
			ans[1] += w.back();
			w.pop_back();
		}
	}
	cout << abs(ans[0] - ans[1]);
}


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

se = [0,0,1]+[1]*998
n = 2
while n ** 2 <= 1000:
    if se[n]:
        nn = 2*n
        while nn <= 1000:
            se[nn] = 0
            nn += n
    n += 1

prime = [x for x in range(0,1001) if se[x]]

ans = 1

for p in prime:
    nn = N
    d = 0
    while True:
        nn //= p
        if not(nn):
            break
        d += nn
    ans *= (d+1)

print(ans%(10**9+7))

Measured memory_bytes: 3064
#include  <iostream>
#include  <vector>
#include  <iomanip>
#include  <algorithm>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector <long double> V(n);
	for (int i = 0; i < n; i++)  cin >> V[i];

	sort(V.begin(), V.end());
	long double s = (V[0] + V[1]) / 2;;
	for (int i = 2; i < n; i++) {
		s = (s + V[i]) / 2;
	}
	cout << fixed << setprecision(6) << s << endl;
}

Measured memory_bytes: 256
N,L=map(int,input().split())

ans=0
if L<1-N:
    ans=(N-1)*(L-1)+(N-1)*N//2
elif 0<=L:
    ans=(N-1)*(L-1)+N*(N+1)//2-1
else:
    ans=N*(L-1)+N*(N+1)//2

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
using namespace std;

const int mod = 1e9 + 7;
int binomialCoeff(int n, int r) {
    int res = 1;
    if(r > n - r)r = n - r;
    for(int i = 0; i < r; i++) {
        res *= (n - i);
        res /= (i + 1);
    }
    return res;
}


int power(int x, int n, int mod) {
    //(x^n)%mod
    int result = 1;
    while(n) {
        if(n % 2)
            result = (result * x) % mod;
        x = (x * x) % mod;
        n /= 2;
    }
    return result;
}

int inverseMod(int x, int mod) {
    return power(x, mod - 2, mod);
}


int32_t main() {

    fast
    int n;
    cin >> n;

    vector<int>x(n);
    vector<int>y(n);
    int a, b, c, d;
    a = c = INT_MIN;
    b = d = INT_MAX;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        a = max(a, x[i] + y[i]);
        b = min(b, x[i] + y[i]);
        c = max(c, x[i] - y[i]);
        d = min(d, x[i] - y[i]);
    }
    vector<pair<int, int>>as, bs, cs, ds;
    for(int i = 0; i < n; i++) {
        if(x[i] + y[i] == a && as.empty()) {
            as.push_back({x[i], y[i]});
        }
        if(x[i] + y[i] == b && bs.empty()) {
            bs.push_back({x[i], y[i]});
        }
        if(x[i] - y[i] == c && cs.empty()) {
            cs.push_back({x[i], y[i]});
        }
        if(x[i] - y[i] == d && ds.empty()) {
            ds.push_back({x[i], y[i]});
        }
    }
    int ans = INT_MIN;
    for(auto &i : as) {
        for(auto &j : bs) {
            ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
        }
    }
    for(auto &i : cs) {
        for(auto &j : ds) {
            ans = max(ans, abs(i.first - j.first) + abs(i.second - j.second));
        }
    }
    cout << ans;




    return 0;
}



Measured memory_bytes: 6340
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		int N = Integer.parseInt(in.readLine());
		String S = in.readLine();
		int K = Integer.parseInt(in.readLine());
	
		in.close();
		
		char target = S.charAt(K-1);
		char[] str = S.toCharArray();
		for(int i = 0 ;i < str.length; ++i) {
			if(str[i] != target) {
				str[i] = '*';
			}
		}
		String result = new String(str);
		System.out.println(result);
		

	}

}

Measured memory_bytes: 23124
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

const int nmax = 1e9 + 7;
const long long INF = 1e16;
typedef long long ll;

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

  vector <int> C(N);
  int M = 0;
  for (int i = 0; i < N; i++) {
    cin >> C[i];
    if(M < C[i]) M = C[i];
  }

  vector <ll> ref(M);

  ll ans = 1;
  ref[C[0] - 1]++;
  for (int i = 1; i < N; i++){
    if(C[i] != C[i - 1]){
      int color = C[i] - 1;
      ans += ref[color];
      ans %= nmax;
      ref[color] = ans;
    }
  }
  cout << ans << endl;


  return 0;
}


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

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

  int n, k;
  cin >> n >> k;

  int ans = 0;

  while (n) {
    n /= k;
    ++ans;
  }

  cout << ans << '\n';

  return (0);
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int x, add;
    cin >> x >> add;
    cout << ((x+add) % 24) << endl;
    return 0;
}


Measured memory_bytes: 3616
sx, sy, tx, ty = map(int, input().split())
x, y = tx - sx, ty - sy
ans = ''
ans += 'L' + 'U' * (y + 1) + 'R' * (x + 1) + 'D'
ans += 'L' * x + 'D' * y
ans += 'R' * x + 'U' * y
ans += 'R' + 'D' * (y + 1) + 'L' * (x + 1) + 'U'
print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> primeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(long i=s;i<e;i++)
#define repeq(i,s,e) for(long i=s;i<=e;i++)



int main() {
	ll a,b;
	in(a);
	in(b);

    if(a<=5)  outn(0);
    else if(a<=12)  outn(b/2);
    else  outn(b);

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    long long q(1);//cin>>q;
    while(q--){
      string s;cin>>s;
      if(s[s.length()-1]!='s')
        cout<<s<<"s"<<endl;
      else
        cout<<s<<"es"<<endl;
    }
}


Measured memory_bytes: 3660
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

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

using namespace std;

char a;
int main(){
  cin >> a;
  if(a == 'A') cout << 'T' << endl;
  else if(a == 'T') cout << 'A' << endl;
  else if(a == 'G') cout << 'C' << endl;
  else if(a == 'C') cout << 'G' << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
 //  Find the minimum number of coins the sum of which is S (we can use as many coins of one type as we want), or report that it’s not possible to select coins in such a way that they sum up to S.



int main()
{
  ios_base::sync_with_stdio(false);

ll arr[3];
cin>>arr[0]>>arr[1]>>arr[2];

sort(arr,arr+3);

if((arr[0]==arr[1]|| arr[1]==arr[2])&&arr[0]!=arr[2])cout<<"Yes"<<"\n";
else cout<<"No"<<"\n";


return 0;

}

Measured memory_bytes: 384
//




#include <bits/stdc++.h>
using namespace std;


#define spdio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define pp pop_back()
#define pf push_front
#define ppf pop_front()
#define ff first
#define ss second
#define mp make_pair
#define fr(i,j,n) for(ll i=j; i<n; i++)
#define rfr(i,j,n) for(ll i=n-1; i>=j; i--)
#define pll pair<ll,ll>
#define plb pair<ll,bool>
#define psl pair<string,ll>
#define psb pair<string,bool>
#define srt(v) sort((v).begin(),(v).end())
#define ub(v,val) upper_bound((v).begin(),(v).end(),(val))-(v).begin()
#define lb(v,val) lower_bound((v).begin(),(v).end(),(val))-(v).begin()


typedef long double ld;
typedef long long int ll;


//getline(cin,string);
const ll inf = (ll) 1e18 + 19;
const ll mod = (ll) 1e9  +  7;




ll ncr(ll n,ll r) {
    ll val=1,i,j,p=2;
    rfr(i,n-r+1,n+1) {
        val*=i;
        while(val%p==0 && p<=r) {
            val/=p;
            p+=1;
        }
    }
    if(p<r) {
        fr(i,p,r+1) val/=i;
    }
    return val;
}




void cazz() {
    ll t=1,i=0,j,n;
    //cin>>t;
    while(t--) {
        cin>>n;
        ll a[n],ans=0;
        fr(i,0,n) cin>>a[i];
        fr(i,1,n) {
            if(a[i-1]>a[i]) {
                ans+=(a[i-1]-a[i]);
                a[i]=a[i-1];
            }
        }
        cout<<ans<<"\n";
    }
}




int main() {
    spdio;
	cazz();
	return 0;
}


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

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

int main() {
  int n;
  cin >> n;
  long long sum = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
        for (int k = 1; k <= n; k++) {
            sum += gcd(i, gcd(j, k));
        }
    }
  }
  cout << sum;
}

Measured memory_bytes: 3608
N=int(input())
count=0
T,X,Y=0,0,0
for i in range(N):
    t,x,y=map(int,input().split())
    if abs(x-X)+abs(y-Y)<=t-T and t%2==(x+y)%2:count+=1
    T,X,Y=t,x,y
print("Yes" if count==N else "No")

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

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int,bool>> content;

    content.push_back(make_pair(1,true));
    for (int i = 1; i < N;i++)
    {
        content.push_back(make_pair(1,false));
    }

    int x, y;
    int possible_locations = 1;
    for (int i =0; i< M;i++)
    {
        cin >> x >> y;
        if (content[x - 1].second && !content[y - 1].second) {
            content[y - 1].second = true;
            possible_locations++;
        }

        if (content[x - 1].first - 1 == 0) // It gets empty
        {
            ++content[y - 1].first;
            --content[x - 1].first;
            if (content[x - 1].second) {
                possible_locations--;
                content[x - 1].second = false;
            }

        }
        else if (content[x - 1].first - 1> 0)
        {
            --content[x - 1].first;
            ++content[y - 1].first;
        }

    }

    cout << possible_locations;


    return 0;
}


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

#define ll long long
#define ull unsigned long long

using namespace std;

const ll INF = 10010010010;

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

	vector <pair<ll,ll>> r(N);
	for (int ii = 0; ii < N; ++ii){
		ll X, L;
		cin >> X >> L;
		int val1 = 
		r[ii].first = X + L;
		r[ii].second = X - L;
	}

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

	ll ans = 0;
	ll tmp = -INF;
	for (int ii = 0; ii < N; ++ii){
		if (tmp <= r[ii].second) {
			ans++;
			tmp = r[ii].first;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
#include <string.h>
#define LEN 100005
 
typedef struct pp {
  char name[100];
  int t;
} P;
 
P Q[LEN];
int head, tail, n;
 
void enqueue(P x) {
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}
 
P dequeue() {
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}
 
int min(int a,int b) {
  return a < b ? a : b; 
}
 
int main() {
  int elaps = 0, c;
  int i, q;
  P u;
  
  scanf("%d %d",&n ,&q);
  for(i=1; i<=n; i++) {
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1; tail = n + 1;
 
  while(head != tail) {
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    elaps += c;
    if(u.t > 0) enqueue(u);
    else {
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}


Measured memory_bytes: 12844
#include<bits/stdc++.h>
 using namespace std;
int gcd(int a, int b){
 return __gcd(a,b);
}

int main(){
  int n;
  std::cin >> n;
  unsigned long long ans = 0;

  for(int i=1; i<=n; i++){
  	for(int j=1; j<=n; j++){
      for(int k=1; k<=n; k++){
       	 ans += gcd(gcd(i, j), k);
      }
    }
  }

  cout << ans << std::endl;

  return 0;
}



Measured memory_bytes: 3620
//chiragjn
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define gibe_de_fast_io_b0ss ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
const ll mod = 1e9 + 7;
const ll INF = 0x7FFFFFFFFFFFFFFF/2;
ll cache[101][100001];
int main(){
    gibe_de_fast_io_b0ss;
    ll n, w, wi, vi;
    cin>>n>>w;
    int answer = 0;
    for(int j = 0; j <= 100000; j++) {
    	cache[0][j] = w + 1LL;
    }
    cache[0][0] = 0;
    for(int i = 1; i <= n; i++) {
    	cin>>wi>>vi;
    	for(int j = 0; j <= 100000; j++) {
    		cache[i][j] = cache[i - 1][j];
    	}
    	for(int j = vi; j <= 100000; j++) {
    		cache[i][j] = min(cache[i][j],  cache[i - 1][j - vi] + wi);
    		
    	}
    	for(int j = 0; j <= 100000; j++) {
    		if(cache[i][j] <= w) {
    			answer = max(answer, j);
    		}
    	}
    }
    cout<<answer;
    return 0;
}


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

int main(){
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;

    for(int i=0; i<=n-2; i++){//Xの最後の文字のite
        map <char,int> table;
        int tmp = 0;
        for(int j=0; j<n; j++){
            if(j <= i){ //前半
                if(!table.count(s[j])){
                    table[s[j]] = 1;
                }
            }
            else{       //後半
                if(table.count(s[j])){
                    if(table.at(s[j]) == 1){
                        tmp ++;
                        table.at(s[j])++;
                        
                    }
                }
            }
        if(ans < tmp){
            ans = tmp;
        }
        }
    }

    cout << ans << endl;

}

Measured memory_bytes: 3604
#include<string>
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>

using namespace std;
int n;
priority_queue<string, vector<string>, greater<string>> Q;
pair<string, int> s[109];
int checked[109];

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

    while(!Q.empty()){
        int cur_ind=-1, mx_val=-1;
        for(int i=0;i<n;i++){
            if(checked[i]==0 && s[i].first==Q.top() && s[i].second > mx_val){
                mx_val = s[i].second;
                cur_ind=i;
            }
        }
        if(cur_ind==-1){
            Q.pop();
        }
        else{
            checked[cur_ind] = 1;
            cout << cur_ind+1 << endl;
        }
    }
}

int main(){
    cin >> n;
    string tmps;
    int tmp;
    for(int i=0;i<n;i++){
        cin >> tmps >> tmp;
        Q.push(tmps);
        s[i].first=tmps;
        s[i].second=tmp;
    }
    solve();
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<long> a;
    for(int i = 0; i < n; i++){
        long t;
        cin >> t;
        a.push_back(t);
    }
    sort(a.begin(), a.end());
    vector<long> twos;
    twos.push_back(1);
    for(long i = 1; i <= a[a.size()-1]; i*=2){
        twos.push_back(2*i);
    }
    long ans = 0;
    int t;
    for(int i = 0; i < a.size(); i++){
        t = 1;
        while(true){
            if(a[i] % twos[t] == 0){
                t++;
            } else {
                t--;
                break;
            }
        }
        ans += t;
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  int x,a,b;
  cin >> x >> a >> b;
  
  int zangaku = (x - a - ((x-a)/b)*b);
  if(zangaku>0){
    cout << zangaku << endl;
  }else{
    cout << 0 << endl;
  }
}

Measured memory_bytes: 256
<?php

  fscanf(STDIN,"%d %d %d",$n,$a,$b);
  
  if($a < $b){
    $max_num = $a;
  }else{
    $max_num = $b;
  }
  
  $min_num = $a+$b-$n;
  if($min_num < 0){
    $min_num=0;
  }
  
  printf("%d %d\n",$max_num,$min_num);
  
?>



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

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

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
using Graph = vector<vector<char>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}
int factorial(int a){
  int res = 1;
  while(a){
    res *= a;
    a--;
  }
  return res;
}


int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A == B && B == C) cout << "Yes" << endl;
  else cout << "No" << endl;

}

Measured memory_bytes: 256