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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

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

#define FF first
#define SS second

template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class T>
istream& operator>>(istream& is, vector<T>& xs){
  for(auto& x: xs)
	is >> x;
  return is;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T>& xs){
  for(unsigned int i=0;i<xs.size();++i)
	os << (i?" ":"") << xs[i];
  return os;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}
void debug(istringstream&){}
template <char sep=',', class Head, class... Tail>
void debug(istringstream& iss, Head&& head, Tail&&... tail)
{
  string name;
  getline(iss, name, ',');
  cerr << sep << name << "=" << head;
  debug(iss, forward<Tail>(tail)...);
}
#define DEBUG(...) \
  do{ \
    istringstream ss(#__VA_ARGS__); \
    debug<' '>(ss, __VA_ARGS__); \
    cerr<<endl; \
  }while(0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  LL N, H , W;
  cin >> N >> H >> W;

  cout << (N-H+1) * (N-W+1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a, b, c;
  int min;
  scanf("%d %d %d", &a, &b, &c);
  min = b+c;
  if(c+a < min){
    min = c+a;
  }
  if(a+b < min){
    min = a+b;
  }
  printf("%d\n", min);
  return 0;
}


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

int main() {

    ll N;
    cin >> N;
    set<string> S;

    string str;
    ll cnt = 0;

    for (int i=0 ; i< N ; i++){
        cin >> str;
        S.insert(str);
        cnt = S.size();
    }   
    
    cout << cnt << endl;

}


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

int main(){
  ll n,k;
  cin>>n>>k;
  ll a[200005];
  rep(i,n) cin>>a[i];
  ll l=0,r=1e9;
  while(l+1<r){
    ll c=(l+r)/2;
    ll sum=0;
    rep(i,n){
      sum+=(a[i]+c-1)/c-1;
    }
    if(sum<=k) r=c;
    else l=c;
  }
  cout<<r<<endl;
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    if(N < 10) {
        if (N == 2 || N == 4) {
            cout << "hon" << endl;
        }
        if (N == 5 || N == 7) {
            cout << "hon" << endl;
        }
        if (N == 9) {
            cout << "hon" << endl;
        }
        if (N == 0 || N == 1) {
            cout << "pon" << endl;
        }
        if (N == 6 || N == 8) {
            cout << "pon" << endl;
        }
        if(N == 3) {
            cout << "bon" << endl;
        }
        return 0;
    }
    if(N < 100) {
        N = N % 10;
        if (N == 2 || N == 4) {
            cout << "hon" << endl;
        }
        if (N == 5 || N == 7) {
            cout << "hon" << endl;
        }
        if (N == 9) {
            cout << "hon" << endl;
        }
        if (N == 0 || N == 1) {
            cout << "pon" << endl;
        }
        if (N == 6 || N == 8) {
            cout << "pon" << endl;
        }
        if(N == 3) {
            cout << "bon" << endl;
        }
        return 0;
    }
    if(N < 1000) {
        N = (N % 100) % 10;
        if (N == 2 || N == 4) {
            cout << "hon" << endl;
        }
        if (N == 5 || N == 7) {
            cout << "hon" << endl;
        }
        if (N == 9) {
            cout << "hon" << endl;
        }
        if (N == 0 || N == 1) {
            cout << "pon" << endl;
        }
        if (N == 6 || N == 8) {
            cout << "pon" << endl;
        }
        if(N == 3) {
            cout << "bon" << endl;
        }
        return 0;
    }
}


Measured memory_bytes: 3596
#include<iostream>
#include<vector>
#include<cstdlib>
#include <cmath>
#define INF 100000000
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; }

using namespace std;

int main(){
  int i,j,k,n,d;
  string a[100];
  bool ans = true;
  cin >>n;
  for(i=0;i<n;i++)cin>>a[i];

  for(i=0;i<n-1;i++){
    for(j=i+1;j<n;j++){
      if(a[i]==a[j])ans=false;
    }
  }

  for(i=0;i<n-1;i++){
    if(a[i].back()!=a[i+1].front()){
      ans=false;
    }
  }

  if(ans)cout << "Yes"<<endl;
  else cout <<"No"<<endl;

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (int)1e9
#define endl "\n"
#define ll long long
#define ull unsigned long long

using namespace std;

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

    vector<vector<ll>> arr(n + 1, vector<ll>(2));

    for (ll i = 0; i < m; i++)
    {
        ll a;
        cin >> a;
        string v;
        cin >> v;

        if (v[0] == 'A')
        {
            arr[a][0] = 1;
        }
        else
        {
            if (!arr[a][0])
                arr[a][1]++;
        }
    }
    ll s = 0;
    ll p = 0;

    for (ll i = 1; i <= n; i++)
    {
        s += arr[i][0];
        if (arr[i][0])
            p += arr[i][1];
    }

    cout << s << " " << p << endl;
}


Measured memory_bytes: 5760
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=998244353;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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 (a>b) { a=b; return 1; } return 0; }
struct mint{
    using ull=unsigned long long int;
    ull v;
    mint(ll vv=0){s(vv%mod+mod);}
    mint& s(ull vv){
        v=vv<mod?vv:vv-mod;
        return *this;
    }
    //オーバーロード
    mint operator-()const{return mint()-*this;}//符号反転
    mint&operator+=(const mint&val){return s(v+val.v);}
    mint&operator-=(const mint&val){return s(v+mod-val.v);}
    mint&operator*=(const mint&val){
        v=ull(v)*val.v%mod;
        return *this;
    }
    mint&operator/=(const mint&val){return *this*=val.inv();}
    mint operator+(const mint&val){return mint(*this)+=val;}
    mint operator-(const mint&val){return mint(*this)-=val;}
    mint operator*(const mint&val){return mint(*this)*=val;}
    mint operator/(const mint&val){return mint(*this)/=val;}
    mint pow(ll n)const{
        mint res(1),x(*this);
        while(n){
            if(n&1)res*=x;
            x*=x;
            n>>=1;
        }
        return res;
    }
     mint inv()const{return pow(mod-2);}
    //拡張ユークリッドの互除法
    /* mint inv()const{
        int x,y;
        int g=extgcd(v,mod,x,y);
        assert(g==1);
        if(x<0)x+=mod;
        return mint(x);
    }*/
    friend ostream& operator<<(ostream&os,const mint&val){
        return os<<val.v;
    }//出力
    bool operator<(const mint&val)const{return v<val.v;}
    bool operator==(const mint&val)const{return v==val.v;}
    bool operator>(const mint&val)const{return v>val.v;}
};
const ll MAX = 2000010;//設定
mint fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void init(){
    fac[0] = fac[1] = 1;
    for(int i=1;i<MAX;i++)fac[i]=fac[i-1]*i;
    finv[MAX-1]=fac[MAX-1].inv();
    for(int i=MAX-2;i>=0;i--)finv[i]=finv[i+1]*(i+1);
    for(int i=MAX-2;i>=1;i--)inv[i]=finv[i]+fac[i-1];
}
//階乗
mint factor(ll n,ll k){
  if (n<k) return 0;
  if (n<0 || k<0) return 0;
  return fac[n]*finv[k];
}
// 二項係数計算
mint COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * finv[k] * finv[n - k];
}
mint dp[505][512];
int main(){
    int n,x;
    cin>>n>>x;
    if(x==0){
        cout<<1<<endl;
        return 0;
    }
    dp[0][0]=1;
    for(int i=1;i<=x;i++){
        for(int j=n-1;j>=0;j--){
            for(int k=0;k<512;k++){
                dp[j+1][i^k]+=dp[j][k];
            }
        }
    }
for(int i=0;i<=x;i++){
    for(int j=1;j<=n-2;j++){
            dp[j+2][x]+=dp[j][x];
        }
    }
    cout<<dp[n-1][x]+dp[n][x]<<"\n";
}



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

int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  
  for(int i=0;i<N;i++){
    cin >> A.at(i);
  }
  int max=A.at(0);
  int n=0;
  for(int i=1;i<N;i++){
    if(max < A.at(i)){
      max = A.at(i);
      n=i;
    }
  }
  
  sort(A.begin(),A.end());
  int m = A.at(N-2);
  
  for(int i=0;i<N;i++){
    if(i != n){
      cout << max << endl;
    }
    else{
      cout << m << endl;
    }
  }
  
}

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

int k;
char s[110];
int main(){
	scanf("%d%s",&k,s);
	int n=strlen(s);
	if(n<=k)puts(s);
	else{
		write(1,s,k);
		write(1,"...",3);
	}
}

Measured memory_bytes: 1624
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    string s;
    lli i,j,k;
    cin>>s;
    if(s=="ABC"){
        cout<<"ARC"<<endl;
    }
    else{
        cout<<"ABC"<<endl;
    }
}


Measured memory_bytes: 3620
using System;
class _0003
{
    public static void Main()
    {
        int dataNum = int.Parse(Console.ReadLine());
        double[] a = new double[dataNum];
        double[] b = new double[dataNum];
        double[] c = new double[dataNum];
        char[] splitChar = { ' ' };
        for (int i = 0; i < dataNum; i++)
        {
            string[] nums = Console.ReadLine().Split(splitChar);
            a[i] = double.Parse(nums[0]);
            b[i] = double.Parse(nums[1]);
            c[i] = double.Parse(nums[2]);
        }
        for (int i = 0; i < dataNum; i++)
        {
            double angle_A = Math.Acos((Math.Pow(b[i], 2.0) + Math.Pow(c[i], 2.0) - Math.Pow(a[i], 2.0)) / (2 * b[i] * c[i])) * 180.0 / Math.PI;
            double angle_B = Math.Acos((Math.Pow(c[i], 2.0) + Math.Pow(a[i], 2.0) - Math.Pow(b[i], 2.0)) / (2 * c[i] * a[i])) * 180.0 / Math.PI;
            double angle_C = Math.Acos((Math.Pow(a[i], 2.0) + Math.Pow(b[i], 2.0) - Math.Pow(c[i], 2.0)) / (2 * a[i] * b[i])) * 180.0 / Math.PI;
            if (angle_A == 90.0 || angle_B == 90.0 || angle_C == 90.0)
            {
                Console.WriteLine("YES");
            }
            else
            {
                Console.WriteLine("NO");
            }
        }
    }
}

Measured memory_bytes: 5868
//FIRST THINK THEN CODE.

  #include <bits/stdc++.h>


  using namespace std;

  typedef long long ll;

  #define rep(i,a,b) for(ll i=a;i<b;++i)
  #define rrep(i,a,b) for(ll i=a;i>b;--i)
  #define FOR(i,n)  for(ll i=0;i<n;i++)
  #define vi vector<int>
  #define vl vector<ll>
  #define ld long double
  #define vld vector<ld>
  #define vvi vector<vector<int>>
  #define vvl vector<vector<long long>>
  #define vvld vector<vector<ld>>
  #define pii pair<int,int>
  #define pll pair<long,long>
  #define vpii vector<pii>
  #define vpll vector<pll>
  #define ff first
  #define ss second
  #define pb push_back
  #define pf push_front
  #define mp make_pair
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define d1(x) cout<<(x)<<endl
  #define d2(x,y) cout<<(x)<<" "<<(y)<<endl
  #define d3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
  #define d4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl
  #define PI 3.1415926535897932384626433832795
  #define fix(f,n) fixed<<setprecision(n)<<f
  #define all(x) x.begin(),x.end()
  #define rev(p) reverse(p.begin(),p.end());
  #define endl "\n"
  #define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  #define popcount(x) __builtin_popcountll(x)
  #define sz(x) ((ll)x.size())
  const ll M=1000000007;
  const ll MM=998244353;
  ll begtime = clock();
  #define end_routine() cout << "\n\nTime elapsed: " << (clock() - begtime)*1000/CLOCKS_PER_SEC << " ms\n\n";
  //#define _Find_next 
  //#define _Find_first 



  ll newmod(ll a,ll b)
  {
  return ((a%b)+b)%b;
  }


  ll powM(ll a,ll b,ll m )
  { 
  if(a<=0)return 0;
  a%=m;
  if(!b)return 1;
  ll ans=1LL;
  while(b)
  {
  if(b&1)ans=ans*a%m;
  a=a*a%m;
  b>>=1;
  }

  return ans;
  }



  ll poww(ll a,ll b)
  { 

  ll ans=1;
  while(b)
  {
  if(b&1)ans=ans*a;
  a=a*a;
  b>>=1;
  }

  return ans;

  }

  template<typename T,typename F>
  void chmax( T &a,F b){
  if(b>a)a=b;
  }

  template<typename T,typename F>
  void chmin( T &a,F b){
  if(b<a)a=b;
  }

string tostring(ll x){
  stringstream sss;
  sss<<x;
  string ans=sss.str();
  return ans;
}


  const ll N=1e3+5;



  int main()
  { 

ll x;cin>>x;

FOR(i,1e6){
  if(i*(i+1)/2>=x){
    cout<<i;
    return 0;
  }
}

  return 0;

  }

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
struct node
{
  int t;
  int f;
  string s;
};

int main()
{
  	string S;
    cin>>S;
    string S_front="",S_back="";
    int Q;
    cin>>Q;
    vector<node>A;

    for(int i=0;i<Q;i++)
    {
      int a;
      node n;
      cin>>a;
      if(a==1)
      {
        n.t=a;
        n.f=0;
        n.s="";
      }
      else
      {
        int b;
        cin>>b;
        string c;
        cin>>c;
        n.t=a;
        n.f=b;
        n.s=c;
      }
      A.push_back(n);

    }
    bool reversed=false;
    for(int i=0;i<Q;i++)
    {
      if(A[i].t==1)
        reversed=!reversed;
      else
      {
        if(!reversed)
        {
          if(A[i].f==1)
          {
            S_front=A[i].s+S_front;
          }
          else
          {
            S_back=S_back+A[i].s;
          }
        }
        else
        {
          if(A[i].f==2)
          {
            S_front=A[i].s+S_front;
            
          }
          else
          {
            S_back=S_back+A[i].s;
          }

        }
      }
    }

    if(!reversed)
    {
      cout<<S_front+S+S_back<<endl;
    }
    else
    {
      S=S_front+S+S_back;
      for(int i=S.length()-1;i>=0;i--)
      {
        cout<<S[i];
      } 
      cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 14192
s = input(); n = len(s)
dp = [ [0,1<<32] for i in range(2) ]
for i in range(n):
  d = ord(s[i])-ord('0')
  dp[(i+1)%2][0] = min(dp[i%2][0], dp[i%2][1])+d
  dp[(i+1)%2][1] = min(dp[i%2][0], dp[i%2][1]-2)+11-d
print(min(dp[n%2][0],dp[n%2][1]))

Measured memory_bytes: 53136
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a!=b&&b!=c&&a!=c)
        cout<<3;
    else if(a!=b&&b==c||a!=c&&b==a||a!=b&&a==c)
        cout<<2;
    else
        cout<<1;

    return 0;
}


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

int kaibun(char *s){
  int i,len;
  len=strlen(s);
  //printf("%d %s\n",len,s);
  
  for(i=0;i<len/2;i++){
    if(s[i]!=s[len-1-i]){
      return 0;
    }
  }
  return 1;
} 

int main(){
  int i,len;
  char input[100],tmp[100]={'\0'};
  
  scanf("%s",input);
  len=strlen(input);
  
  if( kaibun(input) == 0){
    printf("No");
    return 0;
  }
  
  for(i=0;i<(len-1)/2;i++){
    tmp[i]=input[i];
  }
  if( kaibun(tmp) == 0){
    printf("No");
    return 0;
  }
  
  for(i=(len+3)/2-1;i<len;i++){
    tmp[i]=input[i];
  }
  if( kaibun(tmp) == 0){
    printf("No");
    return 0;
  }
  
  printf("Yes");
}

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

long long anum, bnum, cnum;

int main(){
	string S;
	cin >> S;
	for(long long i = 0; i < S.size(); i++){
		if(S[i] == 'a'){
			anum++;
		}else if(S[i] == 'b'){
			bnum++;
		}else{
			cnum++;
		}
	}

	if(max(anum, max(bnum, cnum)) - min(anum, min(bnum, cnum)) >= 2){
		cout << "NO" << endl;
	}else{
		cout << "YES" << endl;
	}

}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int n = s.size();
	string t = "";
	for(int i = 0; i < n; ++i){
		if(s[i] != 'B'){
			t += s[i];
		}
		else{
			if(t.size() > 0)t = t.substr(0, t.size() - 1);
		}
	}
	cout<<t<<endl;
	return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <ctype.h>
const int bufSize = 1e6;
inline char nc()
{
    #ifdef DEBUG
    return getchar();
    #endif
    static char buf[bufSize], *p1 = buf, *p2 = buf;
    return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, bufSize, stdin), p1 == p2) ? EOF : *p1++;
}
inline void read(char *s)
{
    static char c;
    for (; !isalpha(c); c = nc());
    for (; isalpha(c); c = nc()) *s++ = c;
    *s = '\0';
}
template<typename T>
inline T read(T &r)
{
    static char c;
    static int flag;
    flag = 1, r = 0;
    for (c = nc(); !isdigit(c); c = nc()) if (c == '-') flag = -1;
    for (; isdigit(c); c = nc()) r = r * 10 + c - 48;
    return r *= flag;
}
const int maxn = 2e6 + 100;
int n,k;
int a[maxn];
int main()
{
    read(n),read(k);
    for(int i = 1;i<=n;++i) read(a[i]);
    for(int i = k + 1;i<=n;++i)
    {
        if(a[i] > a[i-k]) puts("Yes");
        else puts("No");
    }
    return 0;
}

Measured memory_bytes: 3248
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#define REP(i,n)    for(int i = 0; i < (int)n; i++)
#define MAX_N   100000
typedef long long ll;

void solve(){
    int a, b;
    cin >> a >> b;
    if((b + a) % 2)
        cout << "IMPOSSIBLE\n";
    else{
        int ans = (b + a) / 2;
        if(ans < 0)
            ans *= -1;
        cout << ans << endl;
    }  

}

int main(){
    solve();
    return 0;
}

Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline
inpl = lambda: list(map(int,input().split()))

def bellman_ford(start, goal, N, edges,
                 get_route=False,
                 negative_loop=None,
                 start_distance=0,
                 plus_func=lambda D,d: D+d):
    '''
    goal: int or list or set
    edges: list or dict
        edges[x] = {(y0, distance0), ...}
    '''
    distance = [None]*N
    predecessor = [None]*N
    if isinstance(goal, int):
        goal = [goal]
    elif isinstance(goal, set):
        goal = list(goal)
    M = len(goal)
    goalable = [[False]*N for _ in range(M)]
    for m in range(M):
        goalable[m][goal[m]] = True
    distance[start] = start_distance
    for _ in range(N-1):
        for i in range(N):
            if distance[i] is None:
                continue
            for j, d in edges[i]:
                for m in range(M):
                    if goalable[m][j]:
                        goalable[m][i] = True
                p = plus_func(distance[i], d)
                if distance[j] is None or distance[j] > p:
                    distance[j] = p
                    predecessor[j] = i

    goal_valid = [True]*M
    for i in range(N):
        if distance[i] is None:
            continue
        for j, d in edges[i]:
            if distance[j] is not None and plus_func(distance[i], d) < distance[j]:
                # Negative loop detected.
                for m in range(M):
                    if goal_valid[m] and goalable[m][i]:
                        distance[goal[m]] = negative_loop
                        goal_valid[m] = False
    if get_route:
        return distance, predecessor
    else:
        return distance

N, M, P = inpl()
uv = [ set() for _ in range(N) ]
for i in range(M):
    a, b, c = inpl()
    a -= 1
    b -= 1
    uv[a].add((b,-c+P))

distance = bellman_ford(0, N-1, N, uv)
minus_ans = distance[-1]
if minus_ans is None:
    print(-1)
elif minus_ans > 0:
    print(0)
else:
    print(-minus_ans)


Measured memory_bytes: 56540
#include <iostream>
#include <string>

using namespace std;

int main(){
	int H, W;
	string str[50];
	int cost[50][50];
	while(cin >> H >> W){
		for(int i=0;i<H;i++) cin >> str[i];
		cost[0][0] = 0;
		for(int i=1;i<W;i++) cost[0][i] = cost[0][i-1] + (str[0][i]-'0');
		for(int i=1;i<H;i++) cost[i][0] = cost[i-1][0] + (str[i][0]-'0');
		for(int i=1;i<H;i++)
			for(int j=1;j<W;j++)
				cost[i][j] = min(cost[i][j-1], cost[i-1][j]) + str[i][j]-'0';
		cout << cost[H-1][W-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
import numpy as np
N=int(input())
A=np.array(list(map(int,input().split())))
B=list(map(int,input().split()))
C=np.array(list(map(int,input().split())))

sb=sum(B)
dC=np.diff(A)

sC=C[A[np.where(dC==1)[0]]-1].sum()
#print(sb, sC)
print(sb+sC)

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

int main(){

  string S; // input string
  cin >> S; 

  long long tmp = 0;
  long long sum = 0;
  int digit = S.size() - 1;

  // bit shift search 
  for (int i = 0; i < (1 << digit); ++i) {
    tmp = S[0] - '0';
    for (int j = 0; j < digit; ++j) {
      if (i & (1 << j)) {
        sum += tmp;
        tmp = 0;
      }
      tmp = tmp * 10 + S[j + 1] - '0';
    }
    sum += tmp;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
using System;

namespace B___Chocolate
{
    class Program
    {
        static void Main (string[] args)
        {
            var n = int.Parse (Console.ReadLine ());
            var input = Console.ReadLine ().Split (' ');
            var d = int.Parse (input[0]);
            var x = int.Parse (input[1]);
            var count = n;
            for (var i = 0; i < n; i++)
            {
                var a = int.Parse (Console.ReadLine ());
                var j = 1;
                for (;;)
                {
                    if (j * a + 1 <= d)
                    {
                        count++;
                        j++;
                    }
                    else
                        break;
                }
            }
            Console.WriteLine (count + x);
        }
    }
}

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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define pll pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  ll X, K, D;
  scanf("%lld %lld %lld", &X, &K, &D);

  ll AX = abs(X);

  ll first_count = AX / D;

  if (first_count > K) {
    ll ans = AX - D * K;
    cout << (ans) << endl;
    return 0;
  }

  ll f_ans = AX - D * first_count;
  ll rest_count = K - first_count;

  if (rest_count % 2 == 0) {
    cout << (f_ans) << endl;
  } else {
    cout << abs(f_ans - D) << endl;
  }
}


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

int factorial(int N){
    if(N<=1)return 1;
    else return N*factorial(N-1);
}

double dist(point p1,point p2){
    return sqrt(pow(p1.first-p2.first,2)+pow(p1.second-p2.second,2));
}

int main(){
    int N;
    vector<point> coordinate;
    cin>>N;
    for(int i=0;i<N;i++)
    {
        int x,y;cin>>x>>y;
        coordinate.emplace_back(make_pair(x,y));
    }
    double res=0;
    for(int i=0;i<N;i++){
        double total=0;
        for(int j=0;j<N;j++){
            if(i==j)continue;
            total+=dist(coordinate[i],coordinate[j])*factorial(N-1);
        }
        res+=total;
    }
    res=res/factorial(N);
    cout << fixed << setprecision(7) << res << endl;
    return 0;
}

Measured memory_bytes: 3852
import sys
sys.setrecursionlimit(10**7)
class BinPartite:
    def __init__(self, N, es):
        self.colors = [0 for i in range(N)]
        self.es = es

    def dfs(self, v, color):
        self.colors[v] = color
        for to in self.es[v]:
            if self.colors[to] == color:
                return False
            if self.colors[to] == 0 and not self.dfs(to, -color):
                return False
        return True

    def color_cnt(self, color):
        return self.colors.count(color)

    def is_bipartite(self):
        return self.dfs(0, 1)


N, M = map(int, input().split())
e_list = [[] for i in range(N)]
for i in range(M):
    a, b = map(lambda x: int(x)-1, input().split())
    e_list[a].append(b)
    e_list[b].append(a)

Bp = BinPartite(N, e_list)
if Bp.is_bipartite():
    b = Bp.color_cnt(1)
    w = Bp.color_cnt(-1)
    print(b*w-M)
else:
    print(N*(N-1)//2 - M)


Measured memory_bytes: 31188
N = int(input())
S = []
ab = []  # if include ab [num, ,] if b start [, 1], if a end [, ,1]
for i in range(N):
    S.append(input())

ab_num = 0

"""
b_start = 0
a_end = 0
for i in range(N):
    s = S[i]
    for j in range(1, len(s)):
        if s[j] == 'B' and s[j-1] == 'A':
            ab_num += 1
    if s[0] == 'B':
        b_start += 1
    if s[len(s)-1] == 'A':
        a_end += 1

print(ab_num + min(a_end, b_start))


BABA
ABABA
BAABBAAB
BBAAAAB
ABABABAB
"""

x_A = 0
B_A = 0
B_x = 0


for i in range(N):
    s = S[i]
    for j in range(1, len(s)):
        if s[j] == 'B' and s[j-1] == 'A':
            ab_num += 1

    if s[0] == 'B':
        if s[len(s) - 1] == 'A':
            B_A += 1
        else:
            B_x += 1
    elif s[len(s) - 1] == 'A':
        x_A += 1

if B_A > 0:
    if x_A * B_x > 0:
        print(ab_num + B_A-1 + 2 + min(x_A-1, B_x-1))
    else:
        if x_A + B_x > 0:
            print(ab_num + B_A)
        else:
            print(ab_num + B_A-1)
else:
    print(ab_num + min(x_A, B_x))

Measured memory_bytes: 46680
S = input()
ans = (
    7 if S == "SUN" else
    6 if S == "MON" else
    5 if S == "TUE" else
    4 if S == "WED" else
    3 if S == "THU" else
    2 if S == "FRI" else
    1
)

print(ans)

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,X,Y;

vint lis[222222];

const int mod=1000000007;
int fact[222222];
int inv[222222];
int mpow(int n,int m){
    int ret=1;
    while(m){
        if(m&1)ret=ret*n%mod;
        n=n*n%mod;
        m>>=1;
    }
    return ret;
}
signed main(){
    fact[0]=1;
    for(int i=1;i<222222;i++)fact[i]=fact[i-1]*i%mod;
    inv[222222-1]=mpow(fact[222222-1],mod-2);
    for(int i=222222-2;i>=0;i--)inv[i]=inv[i+1]*(i+1)%mod;


    cin>>N>>X>>Y;
    rep(i,N){
        int c,w;
        cin>>c>>w;
        c--;
        lis[c].pb(w);
    }

    vint latte;
    rep(i,N){
        if(lis[i].size()==0)continue;
        sort(all(lis[i]));
        latte.pb(lis[i][0]);
    }

    sort(all(latte));
    latte.pb(INT_MAX);

    vint ei;
    rep(i,N){
        if(lis[i].size()==0)continue;
        int mi=latte[0];
        if(lis[i][0]==mi)mi=latte[1];
        if(lis[i][0]+mi>Y)continue;
        while(lis[i].size()&&lis[i].back()+mi>Y&&lis[i].back()+lis[i][0]>X)lis[i].pop_back();
        ei.pb(lis[i].size());
    }

    int ans=fact[accumulate(all(ei),0ll)];
    rep(i,ei.size())ans=ans*inv[ei[i]]%mod;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 16500
import java.util.*;

public class Main{
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int n = Integer.parseInt(sc.next());

      int[] h = new int[n];
      for(int i=0;i<n;i++){
        h[i] = Integer.parseInt(sc.next());
      }

      int ans = 1;
      int max = h[0];

      for(int i=1;i<n;i++){
        if(h[i-1]<=h[i] && max<=h[i]){
          ans++;
          max = h[i];
        }
      }


      System.out.println(ans);

    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
using P = pair<int, int>;
const int mx = 100005;
int n, m, u, v, s, t, dis[mx*3];
queue<int> qu;
vector<int> node[mx*3];
int main(){
	scanf("%d%d", &n, &m);
	rep(i,m){
		scanf("%d%d", &u, &v);u--;v--;
		node[u].push_back(v+mx);
		node[u+mx].push_back(v+mx*2);
		node[u+mx*2].push_back(v);
	}
	scanf("%d%d", &s, &t);s--;t--;
	qu.push(s); dis[s] = 1;
	while(!qu.empty()){
		int pos = qu.front(); qu.pop();
		for(int it : node[pos]){
			if(dis[it] == 0){
				qu.push(it);
				dis[it] = dis[pos]+1;
			}
		}
	}
	printf("%d\n", dis[t] ? dis[t]/3 : -1);
}

Measured memory_bytes: 17792
//cod2017_qualC_b.cpp
//Sat Nov 10 21:32:29 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	int n;
	cin >> n;
	int a[n];

	int allnum = 1;
	int oddonly = 1;
	for (int i=0;i<n;i++){
		allnum *= 3;
		cin >> a[i];
		if (a[i]%2==0){
			oddonly *= 2;
		}
	}

	int ans = allnum - oddonly;

	cout << ans << endl;

}

Measured memory_bytes: 256
def main():
    n,k=map(int,input().split())
    grid=[[0]*k for _ in range(k)]
    for i in range(n):
        x,y,c=map(lambda x:x,input().split())
        x,y=int(x),int(y)
        p=(x//k+y//k)%2
        if (p==0 and c=="B")|(p==1 and c=="W"): grid[x%k][y%k]+=1
        else: grid[x%k][y%k]-=1

    for i in range(k):
        for j in range(1,k):
            grid[i][j]+=grid[i][j-1]

    for i in range(1,k):
        for j in range(k):
            grid[i][j]+=grid[i-1][j]


    ans=0
    for i in range(k):
        for j in range(k):
            b=grid[i][j]*4+grid[k-1][k-1]-(grid[i][k-1]+grid[k-1][j])*2
            ans=max(ans,n+b,n-b)
    print(ans//2)

if __name__ == "__main__":
    main()

Measured memory_bytes: 56920
import java.util.Arrays;
import java.util.Scanner;

public class Main {
  Scanner sc;

  boolean[][] done;
  int[][] field;

  int[][] ofs = new int[][] { { 0, 1 }, { 1, 0 }, { -1, 0 }, { 0, -1 },
      { 1, 1 }, { 1, -1 }, { -1, -1 }, { -1, 1 } };

  void dfs(int x, int y) {
    if ( done[ y ][ x ] || field[ y ][ x ] == 0 )
      return;

    done[ y ][ x ] = true;
    for ( int[] d : ofs ) {
      dfs( x + d[ 0 ], y + d[ 1 ] );
    }
  }

  void run() {
    for ( ;; ) {
      int w, h;
      w = ni();
      h = ni();

      if ( ( w | h ) == 0 ) {
        break;
      }

      done = new boolean[h + 2][w + 2];
      field = new int[h + 2][w + 2];

      for ( int i = 1; i <= h; ++i ) {
        for ( int j = 1; j <= w; ++j ) {
          field[ i ][ j ] = ni();
        }
      }

      int sum = 0;
      for ( int i = 1; i <= h; ++i ) {
        for ( int j = 1; j <= w; ++j ) {
          if ( !done[ i ][ j ] && field[ i ][ j ] == 1 ) {
            ++sum;
            dfs( j, i );
          }
        }
      }

      System.out.println( sum );
    }
  }

  Main() {
    sc = new Scanner( System.in );
  }

  int ni() {
    return sc.nextInt();
  }

  String ns() {
    return sc.next();
  }

  public static void main(String[] args) {
    new Main().run();
  }

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }
}

Measured memory_bytes: 42840
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int main(){
  char *str[4]={"NA", "YYMM", "MMYY", "AMBIGUOUS"};
  int YYMM, res=0;
  rd(YYMM);
  if(1 <= YYMM/100  &&  YYMM/100 <= 12){
    res += 2;
  }
  if(1 <= YYMM%100  &&  YYMM%100 <= 12){
    res += 1;
  }
  wt_L(str[res]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190526-1

// --- original code ---
// {
//   int YYMM;
//   char *str[4] = {"NA", "YYMM", "MMYY", "AMBIGUOUS"};
//   int res = 0;
// 
//   rd(YYMM);
//   if(1 <= YYMM/100 <= 12) res += 2;
//   if(1 <= YYMM%100 <= 12) res += 1;
//   wt(str[res]);
// }


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

a = []
for i in range(n):
    a.append(int(input()))

if a[0] > 0:
    print(-1)
    exit()

for i in range(1, n):
    if a[i] > i:
        print(-1)
        exit()
    if a[i] > a[i - 1] + 1:
        print(-1)
        exit()

if n == 1:
    print(0)
    exit()

result = 0

if a[n-1] != 0:
    result += a[n-1]

for i in range(2, n):
    j = n - i
    if a[j] != 0 and a[j] != a[j + 1] - 1:
            result += a[j]

print(result)

Measured memory_bytes: 11052
use proconio::input;

fn main() {
    input! {
        n: usize,
        m: usize,
        a: [usize; m],
    }
    let homework = a.iter().fold(0, |sum, x| sum + x);
    match n >= homework {
        true => println!("{}", n - homework),
        false => println!("{}", -1),
    }
}


Measured memory_bytes: 2280
#include "bits/stdc++.h"

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,a) for(int i = 0; i < (a); ++i)

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int UI;

using namespace std;

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

    int n, temp, mini = INT_MAX, maxi = INT_MIN;
    cin >> n;
    REP(i, n)
    {
        cin >> temp;
        mini = min(mini, temp);
        maxi = max(maxi, temp);
    }

    cout << abs(maxi - mini) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>

using namespace std;
#define MAXN 100000
#define MOD 998244353
#define rint register int
#define gc() getchar()
inline int read(rint ans = 0, rint sgn = ' ', rint ch = gc())
{
	for(; ch < '0' || ch > '9'; sgn = ch, ch = gc());
	for(; ch >='0' && ch <='9';(ans*=10)+=ch-'0', ch = gc());
	return sgn-'-'?ans:-ans;
}
#define BUF_SIZE 1000000
#define _END fwrite(_Ob,1,_O-_Ob,stdout), _O = _Ob
#define Outc(a) (*_O++ = a)
char _Ob[BUF_SIZE+5], *_O = _Ob, _Os[25], *_Ot;
template <typename T> inline void Out(T x)
{
	if(!x){Outc('0'); return;} if(x < 0) Outc('-'), x = -x;
	for(_Ot = _Os; x; *_Ot++ = x%10+'0', x /= 10);
	for(; _Ot != _Os; Outc(*--_Ot)); if(_O-_Ob >= BUF_SIZE-50) _END;
}
int fac[3*MAXN+5], efac[3*MAXN+5], N, M, T, ans; char l[MAXN+5], r[MAXN+5], u[MAXN+5], d[MAXN+5];
int L[MAXN+5], R[MAXN+5], U[MAXN+5], D[MAXN+5], LR[MAXN+5], UD[MAXN+5], b[MAXN+5], col[MAXN+5], row[MAXN+5];
inline int e(int s, int n=MOD-2){int a = 1; for(; n; n&1 ? a = 1ll*a*s%MOD : 0, s = 1ll*s*s%MOD, n >>= 1); return a;}
inline int C(int n, int k){return n<0||k<0||n<k?0:1ll*fac[n]*efac[k]%MOD*efac[n-k]%MOD;}
inline int F(int U, int D, int R){return R ? C(U+D+R-1,R-1) : !U&&!D;}
int main()
{
	N = read(), M = read(), scanf("%s%s%s%s",l+1,r+1,u+1,d+1);
	for(rint i = 1; i <= N; L[i] = L[i-1]+l[i]-'0', i++); for(rint i = 1; i <= N; R[i] = R[i-1]+r[i]-'0', LR[i] = LR[i-1]+(r[i]>'0'&&l[i]>'0'), i++);
	for(rint j = 1; j <= M; U[j] = U[j-1]+u[j]-'0', j++); for(rint j = 1; j <= M; D[j] = D[j-1]+d[j]-'0', UD[j] = UD[j-1]+(d[j]>'0'&&u[j]>'0'), j++);
	if(!L[N]&&!R[N]&&!U[M]&&!D[M]) return puts("1"),0; T = max(LR[N],UD[M]); b[0] = 1; for(rint i = 1; i <= T; b[i] = b[i-1]<<1, b[i]<MOD?:b[i]-=MOD, i++);
	T = max(L[N]+R[N]+max(U[M],D[M]),U[M]+D[M]+max(L[N],R[N])); fac[0] = 1; for(rint i = 1; i <= T; fac[i] = 1ll*i*fac[i-1]%MOD, i++);
	efac[T] = e(fac[T],MOD-2); for(rint i = T; i; efac[i-1] = 1ll*i*efac[i]%MOD, i--);
	for(rint i = N; i; row[i] = (row[i+1]+(L[i]>L[i-1]||R[i]>R[i-1]?1ll*b[LR[i]]*F(L[N]-L[i],R[N]-R[i],D[M]):0))%MOD, i--);
	for(rint j = M; j; col[j] = (col[j+1]+(U[j]>U[j-1]||D[j]>D[j-1]?1ll*b[UD[j]]*F(U[M]-U[j],D[M]-D[j],R[N]):0))%MOD, j--);
	for(rint i = N; i; ans = (ans+(L[i]>L[i-1]||R[i]>R[i-1]?1ll*F(L[i-1],R[i-1],U[M])*e(b[LR[i-1]])%MOD*row[i]:0))%MOD, i--);
	for(rint j = M; j; ans = (ans+(U[j]>U[j-1]||D[j]>D[j-1]?1ll*F(U[j-1],D[j-1],L[N])*e(b[UD[j-1]])%MOD*col[j]:0))%MOD, j--); printf("%d\n",ans); return 0;
}

Measured memory_bytes: 6528
#include <iostream>

int main() {
    
    while (true) {
        
        char grade;
        
        int midtermGrade, finalGrade, makeupGrade = 0;
        std::cin >> midtermGrade >> finalGrade >> makeupGrade;
        
        if (midtermGrade == -1 && finalGrade == -1 && makeupGrade == -1) {
            break;
        }
        
        if (midtermGrade + finalGrade >= 80) {
            grade = 'A';
        }
        
        if ((midtermGrade + finalGrade) >= 65 && (midtermGrade + finalGrade) < 80) {
            grade = 'B';
        }
        
        if ((midtermGrade + finalGrade) >= 50 && (midtermGrade + finalGrade) < 65) {
            grade = 'C';
        }
        
        if ((midtermGrade + finalGrade) >= 30 && (midtermGrade + finalGrade) < 50) {
            grade = 'D';
            
            if (makeupGrade >= 50) {
                grade = 'C';
            }
        }
        
        if ((midtermGrade + finalGrade < 30) || (midtermGrade == -1 || finalGrade == -1)) {
            grade = 'F';
        }
        
        
        std::cout << grade << std::endl;
        
    }
    
    return 0;
}


Measured memory_bytes: 3108
n,m=map(int,input().split())

if n>=2 and m>=2:
    print((n-2)*(m-2))
elif n==1 and m>=2:
    print(m-2)
elif m==1 and n>=2:
    print(n-2)
elif n==1 and m==1:
    print(1)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main{

  static int[] parent;
  static int[] size;
  static int N,M;
  static int[] A,B;
  static long count;
  static long[] ans;

  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    N = sc.nextInt();
    M = sc.nextInt();
    A = new int[M];
    B = new int[M];
    ans = new long[M];
    for(int i=0;i<M;i++){
      A[i]=sc.nextInt();
      B[i]=sc.nextInt();
    }
    UnionFindTree(N);
    ans[0]=(long)N*(N-1)/2;
    for(int i=M-1;i>=1;i--){
      if (!same(A[i], B[i])) count+=(long)size[find(A[i])]*size[find(B[i])];
      ans[i] = count;
      union(A[i],B[i]);
    }
    for(int j=1;j<M;j++){
      System.out.println((long)N*(N-1)/2-ans[j]);
    }
    System.out.println((long)N*(N-1)/2);
  }

  static void UnionFindTree(int Size) {
    parent = new int[Size+1];
    size = new int[Size+1];

    for (int i = 1; i < Size+1; i++) {
      makeSet(i);
    }
  }

  public static void makeSet(int x) {
    parent[x] = x;
    size[x] = 1;
  }


  public static void union(int x, int y) {
    if(x==y){}
    else{
      final int xRoot = find(x);
      final int yRoot = find(y);


      if (xRoot != yRoot) {
        parent[yRoot] = xRoot;
        size[xRoot]+=size[yRoot];

      }
    }
  }


  public static int find(int x) {
    if (x != parent[x]) {
      parent[x] = find(parent[x]);
    }
    return parent[x];
  }


  public static boolean same(int x, int y) {
    return find(x) == find(y);
  }
}

Measured memory_bytes: 97108
// In the name of Allah
    // There is no power but from God the Almighty
    // No God except Allah
    #include <bits/stdc++.h>
    #define mp make_pair
    #define f1 first
    #define f2 second
    #define pb push_back
    #define pii pair<int ,int>
    #define ios  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #define int long long
    using namespace std;
    const int mox=1e2+9;
    int dp[mox][mox][2];
    string sa[mox];
    main()
    {
        int n,m;
        cin>>n>>m;
        for(int i=0 ; i<n ; i++)
        {
            cin>>sa[i];
        }
        for(int i=0 ; i<=n ; i++)
        {
            for(int j=0 ; j<=m ; j++)
            {
                dp[i][j][0]=1e9;
                dp[i][j][1]=1e9;
            }
        }
        if(sa[0][0]=='.')
        {
            dp[0][0][0]=0;
        }
        else
        {
            dp[0][0][1]=1;
        }
        for(int i=0 ; i<n ; i++)
        {
            for(int j=0 ; j<m ; j++)
            {
                if(max(i,j)!=0)
                {
                  if(sa[i][j]=='.')
                    {
                    if(j>0)
                    dp[i][j][0]=min(dp[i][j-1][0],dp[i][j-1][1]);
                    else
                    {
                        dp[i][j][0]=min(dp[i-1][j][0],dp[i-1][j][1]);
                    }
                    if(i==0)
                    dp[i][j][0]=min(dp[i][j][0],min(dp[i][j-1][0],dp[i][j-1][1]));
                    else
                    {
                    dp[i][j][0]=min(dp[i][j][0],min(dp[i-1][j][0],dp[i-1][j][1]));
                    }
                    }
                    else
                    {
                     if(j>0)
                    dp[i][j][1]=min(dp[i][j-1][0]+1,dp[i][j-1][1]);
                    else
                    {
                        dp[i][j][1]=min(dp[i-1][j][0]+1,dp[i-1][j][1]);
                    }
                    if(i==0)
                    dp[i][j][1]=min(dp[i][j][1],min(dp[i][j-1][0]+1,dp[i][j-1][1]));
                    else
                    {
                    dp[i][j][1]=min(dp[i][j][1],min(dp[i-1][j][0]+1,dp[i-1][j][1]));
                    }
                    }

                }
            }
        }
        cout<<min(dp[n-1][m-1][0],dp[n-1][m-1][1]);
    }


Measured memory_bytes: 384
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vb vector<bool>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pli pair<ll, int>a
#define pb push_back
#define sz(x) int(x.size())
 
#define mp make_pair
#define all(a) (a).begin(),(a).end()

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
	int n,k; cin >> n >> k;
  int A = (n-1)*(n-2)/2;
  int cnt = A - k;
  if(cnt < 0){
    cout << -1 << endl;
    return 0;
  }
 
  int m = n-1 + cnt;
 
  vector<pii> ans;
  rep(i,n-1) ans.pb(mp(i+1,n));
 
  vector<pii> edge;
  rep(i,n-1) rep(j,i) edge.pb(mp(i+1,j+1));
  rep(i,cnt) ans.pb(edge[i]);
 
  cout << ans.size() << endl;
  rep(i,sz(ans)) printf("%d %d\n", ans[i].first, ans[i].second);
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int n, m;
	cin >> n >> m;
	int res = 1900 * m + 100 * (n - m);
	REP(i, m) res *= 2;
	cout << res << endl;
	return 0;
}
 

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int[][] students = new int[n][n];
			boolean[][] tallest = new boolean[n][n];
			boolean[][] shortest = new boolean[n][n];
			int[][] x = new int[n][n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					students[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 0; i < n; i++){
				int columnMax = -1, maxj = -1;
				for(int j = 0; j < n; j++){
					if(columnMax < students[j][i]){
						columnMax = students[j][i];
                        maxj = j;
                    }
//					columnMax = Math.max(columnMax, students[j][i]);
				}
				for(int j = 0; j < n; j++){
					if(columnMax == students[j][i]){
						tallest[j][i] = true;
						x[j][i] |= 2;
					}
				}
			}
			for(int i = 0; i < n; i++){
				int rowMin = Integer.MAX_VALUE, minj = -1;
				for(int j = 0; j < n; j++){
					if(rowMin > students[i][j]){
						rowMin = students[i][j];
                        minj = j;
                    }
//					rowMin = Math.min(rowMin, students[i][j]);
//					minj = j;
				}
				for(int j = 0; j < n; j++){
					if(rowMin == students[i][minj]){
						shortest[i][minj] = true;
						x[i][minj] |= 1;
					}
				}
			}
			
			Set<Integer> both = new HashSet<Integer>();
            for(int i = 0;i < n;i++){
                for(int j = 0;j < n;j++){
                    if(x[i][j] == 3){
                        both.add(students[i][j]);
                    }
                }
            }
			
            if(both.size() == 1){
            	StringBuilder sb = new StringBuilder();
                for(int v : both){
                    sb.append(v + " ");
                }
                sb.deleteCharAt(sb.length() - 1);
                System.out.println(sb);
            }else{
            	System.out.println(0);
            }
/*			boolean noAns = true;
			StringBuilder sb = new StringBuilder();
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					if(shortest[i][j] && tallest[i][j]){
						sb.append(students[i][j] + " ");
						noAns = false;
					}
				}
			}
			
			if(noAns){
				System.out.println(0);
			}else{
				sb.deleteCharAt(sb.length() - 1);
				System.out.print(sb);
			}
*/		}
		
	}
}

Measured memory_bytes: 19668
#include <cstdio>
#include <cmath>
#include <cstdlib>

int main(void){
	double q;

	while(scanf("%lf", &q)){
		if(q == -1) break;
		double x = 0;
		x = q/2.0;
		while(std::abs(x*x*x - q) >= 0.00001*q){
			x = x - (x*x*x - q) / (3*x*x);
		}
		printf("%.6f\n", x);
	}


	return 0;
}

Measured memory_bytes: 1084
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#define ll long long

/* aとbの最大公約数を求める. */
ll gcd(ll a, ll b) {
	if (b > a) return gcd(b, a);
	if (b == 0) return a;
	return gcd(b, a % b);
}

/* aとbの最小公倍数を求める. */
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return (a / g) * b;
}

int main() {
	int N, M;
	cin >> N >> M;
	ll L = lcm(N, M);
	ll G = gcd(N, M);
	string S, T;
	cin >> S >> T;
	int m = (int)M / G;
	int n = (int)N / G;
	for (int j = 0; j < M; j += m) {
		int i = j / m * n;
		if (S[i] != T[j]) {
			cout << -1 << endl;
			return 0;
		}
	}
	cout << L << endl;
	return 0;
}

Measured memory_bytes: 512