akhauriyash/Code-Regression huggingface dataset:
import bisect

n = int(input())
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
c = [int(x) for x in input().split()]

a = sorted(a)
b = sorted(b)
c = sorted(c)

ans = 0

for x in b:
    aa = bisect.bisect_left(a,x)
    cc = len(c) - bisect.bisect_right(c,x)
    ans += aa * cc

print(ans)



Measured memory_bytes: 23232
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    int count = 0;
    int max = 0;
    for(int i=0 ; i<s.length() ; i++){
      if(s.charAt(i)=='A' || s.charAt(i)=='C' || s.charAt(i)=='G' || s.charAt(i)=='T'){
        count++;
        max = Math.max(count,max);
      }else{
        count=0;
      }
    }
    System.out.println(max);
  }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1, 1, -1,-1,1};
int dy[] = {1, 0, -1, 0, 1, 1,-1,-1};
#define INF 1000000000000
#define MAX 200001
#define MOD 1000000007
ll fac[MAX], finv[MAX], inv[MAX];
const int MX = 1000005;

void dfs(int s,Graph &G,vector<int> &ans,vector<int> &visited){
    visited[s]=1;
    for(auto v:G[s]){
        if(visited[v]) continue;
        ans[v]+=ans[s];
        dfs(v,G,ans,visited);
    }
}

int main(){
    int n,q;cin>>n>>q;
    vector<vector<int>> G(n);
    for(int i=0;i<n-1;i++){
        int a,b;cin>>a>>b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> visited(n,0);
    vector<int> ans(n,0);
    for(int i=0;i<q;i++){
        int p,x;cin>>p>>x;
        p--;
        ans[p]+=x;
    }
    dfs(0,G,ans,visited);
    for(int i=0;i<n;i++) cout<<ans[i]<<' ';
    cout<<endl;
}



Measured memory_bytes: 27392
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,a,b,kk,pk=0,cnt=0;
     cin>>t>>a>>b;
     for(int i=1;i<=t;i++)
     {
         kk=i;
         while(kk>0)
         {
             pk+=(kk%10);
             kk=kk/10;
         }
         if(pk>=a && pk<=b)
            cnt+=i;
         pk=0;
     }
     cout<<cnt<<endl;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pint = pair<int,  int>;
using pll = pair<ll, ll>;
using edge = pair<int, ll>;
using Graph = vector<vector<int>>; 
using WeightedGraph = vector<vector<edge>>;
const ll INF = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

int main(){
  string s;cin >> s;
  int n = s.size();
  int j = n-1;
  int ans = 0;
  for(int i = 0; i < n; ++i){
    if(i >= j){break;}
    if(s[i]==s[j]){--j;continue;}
    if(s[i]=='x'){++ans;}
    else if(s[j]=='x'){++ans;--j;--i;}
    else{ans= -1;break;}
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define foreach(i,n) for(auto &&i:n)
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort(all(x))
#define GSORT(x) sort(all(x), greater<int>())
#define REV(x) reverse(all(x))
#define MAX(x) *max_element(all(x))
#define MIN(x) *min_element(all(x))
#define LOWitr(x, n) lower_bound(all(x), n)
#define UPRitr(x, n) upper_bound(all(x), n)
#define cii(x) int x;cin >> x
#define cill(x) int64 x;cin >> x
#define cis(x) string x;cin >> x
#define co(x) cout << x << endl
#define dump(x)  cout << #x << " = " << (x) << endl
#define truecheck assert
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef long long int64;
template<class T,class U>bool chmax(T &a, const U &b) { if (a<b) { a=b; return true; } return false; }
template<class T,class U>bool chmin(T &a, const U &b) { if (b<a) { a=b; return true; } return false; }
const int INF = 1e9, MOD = 1e9 + 7;
const LL LLINF = 1e16;

int main() {
    fastcin();
    cout << fixed << setprecision(10);
    cill(n);
    cill(a);
    cill(b);

    auto ans = n / (a+b) * a + min(n % (a+b) , a);

    co(ans);
    return 0;
}

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

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

    int rCnt = 0;
    rep (i, n)
        if (s[i] == 'R')
            rCnt++;

    int wCnt = 0;
    int ans = 0;
    rep (i, n)
    {
        if (s[i] == 'W')
            wCnt++;
        else
        {
            if (rCnt - wCnt - 1 < 0)
                break;
            else
            {
                rCnt--;
                ans += wCnt;
                rCnt -= wCnt;
                wCnt = 0;
            }
        }
    }

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


Measured memory_bytes: 3744
#include <iostream>
#include <string>
const int MAXC = 3;
const int MAXN = 1e5+5;
int dp[MAXN][3];
std::string T;
int P, R, S;
int K, N;

int pos(char c) {
  switch (c) {
  case 'p': return 0;
  case 'r': return 1;
  case 's': return 2;
  }
  return -1;
}

int solve() {
  int pts[3] = {S, P, R};
  for (int i = 0; i < N; ++i) {
    int k = pos(T[i]);
    for (int j = 0; j < MAXC; ++j) {
      dp[i][j] = (j == k) ? pts[j] : 0;
      if (i >= K) {
        int nxt = (j + 1) % MAXC;
        int prv = (j + 2) % MAXC;
        dp[i][j] += std::max(dp[i-K][nxt], dp[i-K][prv]);
      }
    }
  }
  int ret = 0;
  for (int i = N-K; i < N; ++i) {
    ret += *std::max_element(dp[i], dp[i] + MAXC);
  }
  return ret;
}

void fastio() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
}

int main() {
  fastio();
  std::cin >> N >> K >> R >> S >> P >> T;
  std::cout << solve() << '\n';
  return 0;
}

Measured memory_bytes: 1664
//#define _GRIBCXX_DEBUG
#include <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <string>
#include <utility>
#include <vector>
using namespace std;

// ?????¬???????????¬??????
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), c.end()

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<double> vd;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<long, long> pil;


// ??°?????????????????¬??????
typedef int Weight;

struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight :
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;


int main() {
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; ++i) {
    if (i%3==0) printf(" %d", i);
    else if (i%10==3) printf(" %d", i);
    else
      for (int j=i; j!=0;) {
        j /=10;
        if(j%10==3) {
          printf(" %d", i);
          break;
        }
      }
  }
  printf("\n");

  return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using ld = long double;

ll a[3] = {2, 3, 5}, c[3], dd;
map<ll, ll> dp;

ll go(ll n) {
    if (n == 0)
        return 0;
    if (n == 1)
        return dd;
    if (dp.count(n))
        return dp[n];
    ll cm = (n < 2e9 ? n * dd : 1e18);
    rep(i, 3) {
        cm = min(cm, n % a[i] * dd + c[i] + go(n / a[i]));
        if (n % a[i])
            cm = min(cm, (a[i] - n % a[i]) * dd + c[i] + go(n / a[i] + 1));
    }
    dp[n] = cm;
    return cm;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll n, t;
    cin >> t;
    rep(z, t) {
        cin >> n;
        rep(i, 3)
            cin >> c[i];
        cin >> dd;
        dp.clear();
        cout << go(n) << '\n';
    }
}



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

int main(){
    string S;
    
    cin >> S;
    int ans_a = 0;
    int ans_b = 0;

    for (int i=0;i<S.size();i++){
        if( i%2  == S[i] - '0' ){
            ans_a++;
        }else{
            ans_b++;
        }
    }
    cout << min(ans_a,ans_b) << endl;
}

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

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

int main() {
    double W, H, x, y; cin >> W >> H >> x >> y;
    int flag = (2*x == W && 2*y == H);
    cout << W * H / 2.0 << " " << flag << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;//溢出会变成负值 
typedef long double ldb;
typedef unsigned long long ull;//自动取模2^64
const double pi=acos(-1.0);
const int mod = 1e9+7; // 998244353;
const int inf = 0x7fffffff;//2^31-1
const ll INF = 0x7fffffffffffffff;
const int dx[]={-1,0,1,0},dy[]={0,1,0,-1};
//ll begin_time=clock();    ll end_time=clock();  cout<<"time = "<<end_time-begin_time<<" ms!"<<endl;
//bool operator < (const mmp &a) const{return x<a.x||x==a.x&&y<a.y;}       //map<int,map<int,int> >z;
//map<int,int>::iterator it;for(it=z.begin();it!=z.end();it++)printf("%d %d\n",it->first,it->second);
//ll poww(ll a,ll b){ll s=1;while(b){if(b&1)s=(s*a)%mod;a=(a*a)%mod;b>>=1;}return s%mod;}  //快速幂取模 
//lower_bound(begin,end,num); 第一个>=num的数字  upper_bound(begin,end,num); 第一个>num的数字 返回地址 
//freopen("input.in","r",stdin);     freopen("output.out","w",stdout);      //文件读写提交 
//reverse(s.begin(),s.end());   //反转字符串        floor(); 向下取整  ceil(); 向上取证 
//数轴上n个点移动到同一位置，移动到该组数字的中位数的总距离最短 
bool isPrime(int n){if(n==2||n==3)return 1;if(n%6!=1&&n%6!=5)return 0;
int t=sqrt(n);for(int i=5;i<=t;i+=6)if(n%i==0||n%(i+2)==0)return 0;return 1;}//判断素数 


int main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	ll a,b,c,d,e,f,g,T;  
//	cin>>T;
	//while(T--)
	{
		cin>>a;
		string b;
		while(a)
		{
			if(a%26==0)
			{
				a--;
				b+='z';
			}
			else 
			b+=(a%26+26-1)%26+'a';
			a/=26;
		}
		reverse(b.begin(),b.end());
		cout<<b<<endl;
	}
	
}



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

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

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#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, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  __MAKE_TIME__  Problem: __PROBLEM__ / Link: __CONTEST_URL__  ----- */


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

	LL N; cin >> N;
	LL n = N;
	LL sum = 0;
	while (n) {
		sum += n % 10;
		n /= 10;
	}
	auto print_yesno = [](LL yes, int mode = 0) {
		if (mode == 0) {
			cout << (yes ? "yes" : "no") << endl;
		}
		else if (mode == 1) {
			cout << (yes ? "Yes" : "No") << endl;
		}
		else if (mode == 2) {
			cout << (yes ? "YES" : "NO") << endl;
		}
		else assert(0);
	};
	print_yesno(N%sum == 0, 1);


	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
int main(){
   int n,r,e;
  scanf("%d",&n);
  scanf("%d",&r);
  if(n>=10){
    e=r;
  }
  else if(n<10){
    e=r+100*(10-n);
  }
  printf("%d",e);
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<list>
#include<queue>
#include<string.h>
#include<functional>
#include<stack>
#include<deque>
#include<string>
#include<limits.h>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#define int long long
using namespace std;

signed main() {
	int S = 999999999ll, G = 9999999990ll;//[S,G)
	while (G - S > 1) {
		int T = (S + G) / 2;
		string K = to_string(T);
		K += "555";
		cout << "?" << " " << K << endl;
		char i; cin >> i;
		if (i == 'N')S = T;
		else G = T;
	}
	//G
	string s = to_string(G);
	set<char>O;
	string q = to_string(G);
	for (char v : q) {
		O.insert(v);
	}
	if (O.size() == 1 && *O.begin() == '9' || O.size() == 2 && *O.begin() == '9' && *++O.begin() == '9') {
		string x = to_string(G);
		while (1) {
			if (x[x.size() - 1] != '0') { cout <<"! "<< x << endl; break; }
			int y = stoll(x);
			x.erase(--x.end());
			string u;
			for (int i = 0; i < x.size()+1; i++) {
				u += '1';
			}
			cout << "?" << " " << u << endl;
			char i; cin >> i;
			if (i == 'Y') { cout << "! " << x << "0" << endl; break; }
		}
		return 0;
	}
	string x = to_string(G);
	while (1) {
		if (x[x.size() - 1] != '0') { cout << "! " << x << endl; break; }
		int y = stoll(x);
		x.erase(--x.end());
		string u;
		for (int i = 0; i < x.size(); i++) {
			u += '9';
		}
		cout << "?" << " " << u << endl;
		char i; cin >> i;
		if (i == 'N') { cout << "! "<< x << "0" << endl; break; }
	}
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define pi 3.14159265358979323846
long long read(){
    long long 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;
}

long long r[400][400];

int main(){
    int n=read();
    for (int i=1;i<=n;i++){
        for (int j=1;j<=n;j++){
            r[i][j]=read();
        }
    }
    int failed=0;
    for (int j=1;j<=n;j++){
        for (int i=1;i<=n;i++){
            if (j==i)   continue;
            for (int k=1;k<=n;k++){
                if (k==i||k==j) continue;
                else if (r[j][k]&&r[i][j]&&r[i][j]+r[j][k]==r[i][k]){
                    r[i][k]=0;
                }
                else if(r[j][k]&&r[i][j]&&r[i][j]+r[j][k]<r[i][k]){
                    failed=1;
                }
            }
        }
    }
    long long ans=0;
    for (int i=1;i<=n;i++){
        for (int j=i+1;j<=n;j++){
            if (r[i][j])  ans+=r[i][j];
        }
    }
    if(failed==0) cout<<ans;
    else           cout<<-1;
    return 0;
}

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

int l[26], r[26], top[26], bottom[26], h, w, d;
bool flag[26], come[26];
string str[55];
vector<int> front[26];

void my_unique(vector<int>& x){
    sort(x.begin(), x.end());
    vector<int>::iterator it = unique(x.begin(), x.end());
    x.erase(it, x.end());
}

int loop(int x){
    if(come[x])return true;
    bool res = false;
    come[x] = true;
    for(int i = 0;i < front[x].size();i++){
	res |= loop(front[x][i]);
    }
    come[x] = false;
    return res;
}

int main(){
    cin >> d;
    while(d--){
	fill(l, l + 26, 100);
	fill(r, r + 26, -1);
	fill(bottom, bottom + 26, 100);
	fill(top, top + 26, -1);
	cin >> h >> w;
	for(int i = 0;i < h;i++){
	    cin >> str[i];
	    for(int j = 0;j < w;j++){
		if(str[i][j] == '.')continue;
		int tmp = str[i][j] - 'A';
		flag[tmp] = true;
		l[tmp] = min(l[tmp], i);
		bottom[tmp] = min(bottom[tmp], j);
		r[tmp] = max(r[tmp], i);
		top[tmp] = max(top[tmp], j);
	    }
	}
	bool res = true;
	for(int s = 0;s < 26;s++){
	    front[s].clear();
	    if(!flag[s])continue;
	    for(int i = l[s];i <= r[s];i++){
		for(int j = bottom[s];j <= top[s];j++){
		    if(str[i][j] == '.')res = false;
		    if(str[i][j] != 'A' + s){
			front[s].push_back(str[i][j] - 'A');
		    }
		}
	    }
	    my_unique(front[s]);
	}
	for(int i = 0;res && i < 26;i++){
	    if(loop(i))res = false;
	}
	if(res)
	    cout << "SAFE" << endl;
	else
	    cout << "SUSPICIOUS" << endl;
    }
    return 0;
}

Measured memory_bytes: 1308
n = int(input())
a = list(map(int, input().split()))
b = [i-num-1 for num,i in enumerate(a)]
d = {}
for i in b:
  if i in d:
    d[i] += 1
  else:
    d[i] = 1
ans = 0
for num,i in enumerate(a):
  if -i-num-1 in d:
    ans += d[-i-num-1]
print(ans)

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

int f(int a){
	int ret = 0;
	for(int i = 1;i <= a;i++){
		if(a%i == 0){
			ret++;
		}
	}
	return ret;
}

int main(){
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 1;i <= n;i++){
		if(f(i) == 8 && i % 2 == 1) cnt++;
	}
	cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef set <int> si;
typedef set <int> :: iterator sitr;
typedef set <ll> :: iterator sltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef mset <int> :: iterator msitr;
typedef mset <ll> :: iterator msltr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
int n;
str s[200];
set<str> w;
int main(){
    cin>>n;
    bool valid=true;
    for(int i=1;i<=n;i++){
        cin>>s[i];
        if(i==1){w.insert(s[i]);}
        else{
            if(w.count(s[i])){valid=false;}
            else if(s[i][0] != s[i-1][s[i-1].size()-1] ){valid=false;}
            else{
                w.insert(s[i]);
            }
        }
    }
    if(valid)cout<<"Yes\n";
    else cout<<"No\n";


}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

int main(){
    ll x,k,d;
    cin>>x>>k>>d;
    x=abs(x);
    ll g=x%d,u=d-x%d;
    if(x/d>k){
        cout<<x-k*d<<endl;
    }
    else{
        ll m=x/d;
        x-=m*d;
        if((k-m)%2==1){
            if(x==g){
                cout<<u<<endl;
            }
            else cout<<g<<endl;
        }
        else{
            if(x==g){
                cout<<g<<endl;
            }
            else cout<<u<<endl;
        }
    }
}


Measured memory_bytes: 3628
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;
import std.bigint;


void main()
{
  auto n = readln.chomp.to!int;
  int sum, m;
  foreach (i; 0..n) {
    auto p = readln.chomp.to!int;
    sum += p;
    m = max(m, p);
  }
  writeln(sum-m/2);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define int long long
using namespace std;

signed main() {
  int n;
  cin >> n;
  for (int c = 0; c < n; c++) {
    string x, y;
    cin >> x >> y;

    int dp[x.size() + 1][y.size() + 1];
    for (int i = 0; i < x.size() + 1; i++) {
      dp[i][0] = 0;
    }

    for (int j = 0; j < y.size() + 1; j++) {
      dp[0][j] = 0;
    }
      
    for (int i = 1; i < x.size() + 1; i++) {
      for (int j = 1; j < y.size() + 1; j++) {
	if (x[i - 1] == y[j - 1]) {
	  dp[i][j] = dp[i - 1][j - 1] + 1;
	} else {
	  dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
	}
      }
    }

    cout << dp[x.size()][y.size()] << endl;
  }

  return 0;
}

Measured memory_bytes: 10868
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>
#include<stack>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
typedef vector<string> vstring;
typedef vector<pint> vpint;
typedef stringstream SS;

struct Edge{int to,from,cost;};

#ifdef DEBUG
#define debug cout
#else
SS ss;
#define debug ss
#endif

template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

#define rep(i,n) for(int i=0;i<(n);++i)
#define repn(i,m,n) for(int i=(m);i<(n);++i)
#define repd(i,n) for(int i=(n)-1;i>=0;--i)
#define repnd(i,m,n) for(int i=(n)-1;i>=(m);--i)
#define rep0(i,n) for(i=0;i<(n);++i)
#define repn0(i,m,n) for(i=(m);i<(n);++i)
#define repd0(i,n) for(i=(n)-1;i>=0;--i)
#define repnd0(i,m,n) for(i=(n)-1;i>=(m);--i)
#define repc(i,n) for(int i=0;i<=(n);++i)
#define repcn(i,m,n) for(int i=(m);i<=(n);++i)
#define repcd(i,n) for(int i=(n);i>=0;--i)
#define repcnd(i,m,n) for(int i=(n);i>=(m);--i)
#define repc0(i,n) for(i=0;i<=(n);++i)
#define repcn0(i,m,n) for(i=(m);i<=(n);++i)
#define repcd0(i,n) for(i=(n);i>=0;--i)
#define repcnd0(i,m,n) for(i=(n);i>=(m);--i)
#define all(n) n.begin(),n.end()
#define sz(n) ((int)(n).size())
#define IL for(;;)
#define MP make_pair
#define PB push_back
#define X second
#define Y first
#define p_queue(n) priority_queue<n,vector<n>,greater<n> >
#define PUTLINE debug<<"LINE:"<<__LINE__<<endl;

const int INF = 2147483647/3;
const double EPS = 1e-10;
const double PI = acos(-1.0);

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

int dis[123][123];
int n,m,s,g1,g2;

int main() {
	IL{
		cin>>n>>m>>s>>g1>>g2;
		if(n+m+s+g1+g2==0)break;
		--s,--g1,--g2;
		rep(i,n)rep(j,n)dis[i][j]=INF;
		rep(i,n)dis[i][i]=0;
		rep(i,m){
			int a,b,c;
			cin>>a>>b>>c;
			--a,--b;
			dis[a][b]=c;
		}
		rep(k,n)rep(i,n)rep(j,n)chmin(dis[i][j],dis[i][k]+dis[k][j]);
		int res=INF;
		rep(i,n)chmin(res,dis[s][i]+dis[i][g1]+dis[i][g2]);
		cout<<res<<endl;
	}
	return 0;
}

Measured memory_bytes: 920
import java.io.*;
import java.io.InputStreamReader;
import java.util.*;
public class Main
{
    static long dist[][];
    static long ans;
    static void solve(int array[], int start, int end) {
        if (start == end) {
            long temp = 0;
            for (int i = 1; i < array.length - 1; i++)
                temp += dist[array[i]][array[i + 1]];
            ans = Math.min(ans, temp);
            return;
        }
        for (int i = start; i <= end; i++) {
            swap(array, start, i);
            solve(array, start + 1, end);
            swap(array, start, i);
        }
    }
    static void swap(int array[], int start, int idx){
        int temp = array[start];
        array[start] = array[idx];
        array[idx] = temp;
    }
 
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int r = Integer.parseInt(st.nextToken());
        int array[] = new int[r + 1];
        st = new StringTokenizer(br.readLine());
        for (int i = 1; i < array.length; i++)
            array[i] = Integer.parseInt(st.nextToken());
        dist = new long[n + 1][n + 1];
        for(int i = 1;i <= n;i++)
            Arrays.fill(dist[i], Long.MAX_VALUE / 2);
        for (int i = 1; i <= m; i++) {
            st = new StringTokenizer(br.readLine());
            int a = Integer.parseInt(st.nextToken());
            int b = Integer.parseInt(st.nextToken());
            int c = Integer.parseInt(st.nextToken());
            dist[a][b] = dist[b][a] = c;
        }
        for (int k = 1; k <= n; k++) {
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= n; j++)
                    dist[i][j] = Math.min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
        ans = Long.MAX_VALUE;
        solve(array, 1, r);
        System.out.print(ans);
    }
 
}

Measured memory_bytes: 30652
#include <stdio.h>
int main(){
	int N, hurufK;
	
	scanf("%d %d", &N, &hurufK);
	char kata[N+1];
	scanf("%s", &kata);
	
	kata[hurufK-1] = kata[hurufK-1]+32;
	
	printf("%s\n", kata);
	
	
	return 0;
}

Measured memory_bytes: 1612
#include<bits/stdc++.h>
using namespace std;
int main(){
int A1,A2,A3;
cin>>A1>>A2>>A3;
int mx=max(A1,max(A2,A3));
int mn=min(A1,min(A2,A3));
cout<<mx-mn;
return 0;
}


Measured memory_bytes: 3620
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int X = in.Int();
            out.println(X >= 30 ? "Yes" : "No");

        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    return null;
                }
            }
            return st.nextToken();
        }

        public int Int() {
            return Integer.parseInt(next());
        }

    }
}



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

int main(){
  string S, T;
  cin >> S >> T;
  int cnt = 0;
  for (int i = 0; i < S.length(); ++i){
    if (S[i] != T[i]) {
      ++cnt;
    }
  }
  cout << cnt;
  return 0;
}

Measured memory_bytes: 3868
N,M = map(int,input().split())
a = [0]*(N+2)
pass_list = [0]*(N+2)

for i in range(M):
    b = int(input())
    a[b] = 1
if(a[1] !=1):
    pass_list[1]=1
if(a[2] !=1):
    pass_list[2]=1
for i in range(2,N+1):
    if(a[i] != 1):
        pass_list[i] += pass_list[i-1]+pass_list[i-2]
print(pass_list[N]%1000000007)


Measured memory_bytes: 469204
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;

class Team {
public:
    int id, solved, penalty;
    int ac[10], wa[10];
    Team(int id) : id(id), solved(0), penalty(0) {
        memset(ac, 0, sizeof ac);
        memset(wa, 0, sizeof wa);
    }
    bool operator<(const Team& obj)const {
        return solved < obj.solved
            || (solved == obj.solved && penalty > obj.penalty)
            || (solved == obj.solved && penalty == obj.penalty && id > obj.id);
    }
    void correct(int pID, int t) {
        if (ac[pID]) return ;
        ++ solved;
        ac[pID] = 1;
        penalty += wa[pID] * 1200 + t;
    }
    void wrong(int pID) {
        ++ wa[pID];
    }
};

int main() {
    int T, P, R;
    while (cin >> T >> P >> R, T) {
        vector<Team> teams;
        for (int i=1; i<=T; ++i) teams.push_back(Team(i));
        int tID, pID, t;
        string msg;
        for (int i=0; i<R; ++i) {
            cin >> tID >> pID >> t >> msg;
            tID --; pID --;
            if (msg == "CORRECT") {
                teams[tID].correct(pID, t);
            } else if (msg == "WRONG") {
                teams[tID].wrong(pID);
            }
        }
        sort(teams.begin(), teams.end());
        reverse(teams.begin(), teams.end());
        for (int i=0; i<(int)teams.size(); ++i) {
            cout << teams[i].id << " " << teams[i].solved << " " << teams[i].penalty << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main(){
  int a,b;
  vector<string> s = {"Draw","Alice","Bob"};
  cin >> a >> b;
  if(a == b){
    cout << s[0];
  }else if((a > b && b != 1) || a == 1){
    cout << s[1];
  }else{
    cout << s[2];
  }
  return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

ll dx[9] = {-1, 1, 0, 0, -1, -1, 1, 1, 0};
ll dy[9] = {0, 0, -1, 1, -1, 1, -1, 1, 0};

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;
  ll all = 1;
  ll odd = 1;
  rep(i, n) {
    ll x;
    cin >> x;
    all *= 3;
    if (!(x & 1)) odd *= 2;
  }

  cout << all - odd << endl;

  return 0;
}


Measured memory_bytes: 256
require 'prime'

# def _divisors(primes, k)
#   Enumerator.new do |y|
#     if primes.size == k
#       y << 1
#     else
#       p, e = primes[k]
#       _divisors(primes, k + 1).each {|d|
#         (e + 1).times {|e1|
#           y << p ** e1 * d
#         }
#       }
#     end
#   end
# end

# def divisors(n)
#   _divisors(Prime.prime_division(n), 0).to_a.sort
# end

def divisors(n)
  n.prime_division.inject([1]) do |ary, (p, e)|
    (0..e).map{ |e1| p ** e1 }.product(ary).map{ |a, b| a * b }
  end.sort
end

n, m = gets.split.map(&:to_i)
puts m / divisors(m).bsearch { |i| i >= n }


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

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

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll H;
ll i, j, k;

ll calc(ll a){
    if(a==1)
        return 1;
    ll ret = calc(a / 2);
    return ret * 2 + 1;
}
int main(){
    scanf("%lld", &H);
    printf("%lld", calc(H));

    return 0;
}

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

int main() {
    int N, K; cin >> N >> K;
    long long x[N]; 
    for(int i=0; i<N; i++) cin >> x[i];
    
    long long min_cost = 9e18;
    long long cost1, cost2;
    for(int i=0; i<N-K+1; i++){
        cost1 = abs(x[i] - x[i+K-1]) + abs(x[i]);
        cost2 = abs(x[i] - x[i+K-1]) + abs(x[i+K-1]);
        
        min_cost = min(min_cost, min(cost1, cost2));
    }

    cout << min_cost << endl;
}


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

using namespace std;
typedef pair<char, int> P;

void bubbleSort(vector<P>& vec)
{
	for (int i = 0; i < vec.size() - 1; ++i)
	{
		for (int j = vec.size() - 1; j > i; --j)
		{
			if (vec[j].second < vec[j - 1].second)
			{
				P temp = vec[j];
				vec[j] = vec[j - 1];
				vec[j - 1] = temp;
			}
		}
	}
}

void selectionSort(vector<P>& vec)
{
	for (int i = 0; i < vec.size(); ++i)
	{
		int minj = i;
		for (int j = i; j < vec.size(); ++j)
		{
			if (vec[j].second < vec[minj].second)
			{
				minj = j;
			}
		}
		P temp = vec[i];
		vec[i] = vec[minj];
		vec[minj] = temp;
	}
}

void solve()
{
	int n;
	cin >> n;
	vector<P> vec;
	for (int i = 0; i < n; ++i)
	{
		P p;
		cin >> p.first >> p.second;
		vec.push_back(p);
	}
	vector<P> bubbleVec = vec;
	vector<P> selectionVec = vec;
	bubbleSort(bubbleVec);
	selectionSort(selectionVec);

	string bubbleResult = "";
	for (int i = 0; i < bubbleVec.size() - 1; ++i)
	{
		cout << bubbleVec[i].first << bubbleVec[i].second << " ";
		bubbleResult += bubbleVec[i].first;
		bubbleResult += bubbleVec[i].second + '0';
	}
	cout << bubbleVec[bubbleVec.size() - 1].first << bubbleVec[bubbleVec.size() - 1].second << endl;
	bubbleResult += bubbleVec[bubbleVec.size() - 1].first;
	bubbleResult += bubbleVec[bubbleVec.size() - 1].second + '0';
	cout << "Stable" << endl;
	
	string selectionResult = "";
	for (int i = 0; i < selectionVec.size() - 1; ++i)
	{
		cout << selectionVec[i].first << selectionVec[i].second << " ";
		selectionResult += selectionVec[i].first;
		selectionResult += selectionVec[i].second + '0';
	}
	cout << selectionVec[selectionVec.size() - 1].first << selectionVec[selectionVec.size() - 1].second << endl;
	selectionResult += selectionVec[selectionVec.size() - 1].first;
	selectionResult += selectionVec[selectionVec.size() - 1].second + '0';
	if (bubbleResult == selectionResult)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable" << endl;
	}
}

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

Measured memory_bytes: 1220
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main() {
	int N, K;
	vector<int> num;
	int inputNum;
	int answer = 0;

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> inputNum;
		num.push_back(inputNum);
	}

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

	for (int i = 0; i<K; i++) {
		answer += num[N - i - 1];
	}

	cout << answer << endl;

	return 0;
}

Measured memory_bytes: 256
import bisect
import copy
import heapq
import sys
import itertools
import math
import queue
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
mod = 10 ** 9 + 7

def read_values(): return map(int, input().split())
def read_index(): return map(lambda x: int(x) - 1, input().split())
def read_list(): return list(read_values())
def read_lists(N): return [read_list() for n in range(N)]
def init_dp1(init, N): return [init for _ in range(N)]
def init_dp2(init, N, M): return [[init for _ in range(M)] for _ in range(N)]


class V:
    def __init__(self, f, v=None):
        self.f = f
        self.v = v
 
    def __str__(self):
        return str(self.v)
 
    def ud(self, n):
        if n is None:
            return

        if self.v is None:
            self.v = n
            return
        self.v = self.f(self.v, n) 


def main():
    N, M = read_values()

    if N % 2 == 1: 
        L = N // 2
        R = L + 1
        for _ in range(M):
            print(L, R)
            L -= 1
            R += 1
    else:
        L = 1
        R = M + 1
        for _ in range(M, 0, -2):
            print(L, R)
            L += 1
            R -= 1
        
        L = M + 2
        R = 2 * M + 1
        for _ in range(M - 1, 0, -2):
            print(L, R)
            L += 1
            R -= 1


if __name__ == "__main__":
    main()


Measured memory_bytes: 10016
#include <stdio.h>
#include <string.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))

ll n;
ll a[20];
int main(){
	scanf("%lld",&n);
	rep(i,0,n){
		ll t;
		scanf("%lld",&t);
		a[t/400]++;
	}
	ll ans=0;
	ll flag=0;
	rep(i,0,8)ans+=!!a[i];
	rep(i,8,15)flag+=a[i];
	printf("%lld %lld\n",max(ans,1),ans+flag);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long int
   int n,k;
   vector<int> a,b;
  
   int good(int x)
   {
   	int change=0;
   	for(int i=0;i<n;i++)
   	{
   		if(a[i]*b[i]>x)
   		{
 		   change+=(a[i]-x/b[i]);
   		}
   	}

   	return change;
   }

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);    
     cin>>n>>k;
     a.resize(n);
     b.resize(n);
    for(int i=0;i<n;i++)
    	cin>>a[i];
    for(int i=0;i<n;i++)
    	cin>>b[i];
    sort(a.begin(),a.end());
    sort(b.begin(),b.end(),greater<int>());
    int lo=0,hi=1000000000010;
    int ans=0;
    while(lo<hi)

    {
    	int mid=(hi+lo)/2;
    	if(good(mid)<=k)
    	{
    		ans=mid;
    		hi=mid;
    	}
    	else
    		lo=mid+1;
    }

    cout<<ans;


   }



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



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

  bool b = false;

  for(int i = 1; i<=9; ++i) {
    if (N <= 81 && N%i == 0 && N/i <=9 ) b = true; 
  }

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

  return 0;
}

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

ll a,b,c,d,n,m;
ll ans=100000000000;

string s;

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin>>a;
  b=100;
  int i=0;
  while(1){
    i++;
    b *= 1.01;
    if(b>=a)break;
  }
  cout<<i;

  

  return 0;
}



Measured memory_bytes: 3640
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int H, W;
char s[101][101];
int DP[101][101];

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

  cin >> H >> W;
  rep(i, H) rep(j, W) {
    cin >> s[i][j];
    DP[i][j] = INF;
  }
  DP[0][0] = s[0][0] == '#'?1:0;
  rep(i, H) {
    rep(j, W) {
      char c = s[i][j];
      if (i<H-1) {
        char yoko = s[i+1][j];
        if (c=='.'&& yoko=='#') DP[i+1][j] = min(DP[i][j] + 1, DP[i+1][j]);
        else DP[i+1][j] =  min(DP[i][j], DP[i+1][j]);
      }
      if (j<W-1) {
        char tate = s[i][j+1];
        if (c=='.'&& tate=='#') DP[i][j+1] = min(DP[i][j] + 1, DP[i][j+1]);
        else DP[i][j+1] = min(DP[i][j], DP[i][j+1]);
      }
    }
  }

  cout << DP[H-1][W-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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;}

int H,W;

int toid(int y, int x){
  return y*W+x;
}

int main(){
  cin >> H >> W;
  vector<string> S(H);
  rep(i,H) cin >> S[i];
  int ans = 0;
  vector<vector<int>> G(H*W);
  vector<vector<int>> CO(H*W);
  rep(y,H){
    rep(x,W){
      if(y!=H-1){
        G[toid(y,x)].pb(toid(y+1,x));
        CO[toid(y,x)].pb(S[y][x] == S[y+1][x]? 0:1);
      }
      if(x!=W-1){
        G[toid(y,x)].pb(toid(y,x+1));
        CO[toid(y,x)].pb(S[y][x] == S[y][x+1]? 0:1);
      }
    }
  }
  vector<ll> D(H*W, -1);
  vector<bool> used(H*W, false);
  priority_queue<pair<ll,int>,
                 vector<pair<ll,int>>,
                 greater<pair<ll,int>>> q;
  q.push({(ll)0,0});
  while(!q.empty()){
    ll d = q.top().first; int to = q.top().second; q.pop();
    if(used[to]) continue;
    used[to] = true; D[to] = d;
    rep(i,sz(G[to])){
      if(D[G[to][i]] != -1 && D[G[to][i]] <= D[to] + CO[to][i]) continue;
      q.push({D[to] + CO[to][i], G[to][i]});
    }
  }
  //cout << D[H*W-1] << endl;
  ans = (D[H*W-1]+1)/2;
  if(S[0][0]=='#' && S[H-1][W-1]=='#') ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
 
 
 
int main()
{ 
     long long n;
     cin>>n;
     
     vector<int> a(n);
     long long s=0;
     for(long long i=0; i<n; i++)
      cin>>a[i];
     
     for(long long i=1; i<n; i++)
     { if(a[i-1]>a[i])
     	{ s+=abs(a[i-1]-a[i]);
        a[i]=a[i-1];
        }
      
     }


     cout<<s<<endl;

 }

Measured memory_bytes: 3960
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
inline int read()
{
	int f = 1, x = 0;
	char ch;

	do{
		ch = getchar();
		if (ch == '-')
			f = -1;
	}while(ch < '0' || ch > '9');
	do{
		x = x * 10 + ch - '0';
		ch = getchar();
	}while(ch >= '0' && ch <= '9');
	return f * x;
}
const int N = 2e5;

int l, r, n, m, s, t;
struct Edge {
	int	to, next, oppo;
	int	done, maxx;
} edge[(N << 3) + 1];
int tot, start[N + 1], cur[N + 1];
queue<int> q;
int vis[N + 1], dep[N + 1];
int to[N + 1], viss[N + 1];
vector<int> in[N + 1];
int ans;
int ansa[N + 1], ansb[N + 1];

inline void addedge(int u, int v, int flow)
{
	edge[++tot] = Edge{ v, start[u], tot + 1, 0, flow };
	start[u] = tot;
	edge[++tot] = Edge{ u, start[v], tot - 1, 0, 0 };
	start[v] = tot;
	return;
}
inline bool bfs()
{
	for (int i = 0; i <= (n << 1) - 1; i++)
		vis[i] = dep[i] = 0;
	q.push(s);
	dep[s] = vis[s] = 1;
	while (q.size()) {
		int u = q.front();
		q.pop();
		for (int i = start[u]; i; i = edge[i].next) {
			int v = edge[i].to;
			if (!vis[v] && edge[i].done < edge[i].maxx) {
				dep[v] = dep[u] + 1;
				vis[v] = 1;
				q.push(v);
			}
		}
	}
	return dep[t];
}
inline int dfs(int u, int flow)
{
	if (u == t || !flow)
		return flow;
	int val = 0;
	for (int &i = cur[u]; i; i = edge[i].next) {
		int v = edge[i].to;
		if (dep[v] == dep[u] + 1) {
			int w = dfs(v, min(flow, edge[i].maxx - edge[i].done));
			if (w > 0) {
				edge[i].done += w;
				edge[edge[i].oppo].done -= w;
				val += w;
				flow -= w;
				if (!flow)
					break;
			}
		}
	}
	return val;
}
inline void dinic()
{
	while (bfs()) {
		for (int i = 0; i <= (n << 1) - 1; i++)
			cur[i] = start[i];
		ans += dfs(s, 2147483647);
	}
	return;
}
inline int solve()
{
	for (int i = 1; i < n; i++) {
		for (int j = start[i]; j; j = edge[j].next) {
			if (edge[j].to)
				if (edge[j].done)
					to[i] = edge[j].to - n + 1;
		}
	}
	q.push(n);
	int link = 0;
	while (!q.empty()) {
		int u = q.front();
		q.pop();
		for (int i = 0; i < in[u].size(); i++) {
			int v = in[u][i];
			if (viss[v])
				continue;
			link++;
			ansa[v] = u;
			ansb[v] = to[v];
			q.push(to[v]);
			viss[v] = 1;
		}
	}
	return link;
}
int main()
{
	n = read();
	s = 0;
	t = (n << 1) - 1;
	for (int i = 1; i < n; i++) {
		int k = read();
		for (int j = 1; j <= k; j++) {
			int x = read();
			if (x != n)
				addedge(i, n + x - 1, 1e9);
			in[x].push_back(i);
		}
	}
	for (int i = 1; i < n; i++)
		addedge(0, i, 1);
	for (int i = 1; i <= n; i++)
		addedge(i + n - 1, (n << 1) - 1, 1);

	dinic();

	if (ans < n - 1) {
		printf("-1\n");
		return 0;
	}
	if (solve() < n - 1) {
		printf("-1");
		return 0;
	}
	for (int i = 1; i < n; i++)
		printf("%d %d\n", ansa[i], ansb[i]);
	return 0;
}


Measured memory_bytes: 32944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class Main {
	public static void main(String[] args) throws IOException {
		try (AtCoderReader ar = new AtCoderReader()) {

			int[] input = ar.nextIntArray();

			int N = input[0];
			int Y = input[1];

			System.out.println(getAns(N, Y));
		}
	}

	private static String getAns(int N, int Y) {
		for (int i = 0; i <= N; i++) {
			for (int j = 0; i + j <= N; j++) {
				int k = N - (i + j);
				if (isMatch(Y, k, j, i)) {
					return String.join(" ", String.valueOf(k), String.valueOf(j), String.valueOf(i));
				}
			}
		}
		return "-1 -1 -1";
	}

	private static boolean isMatch(int price, int d100, int d50, int d10) {
		return price == (d100 * 10000 + d50 * 5000 + d10 * 1000);
	}

	public static class AtCoderReader implements AutoCloseable {
		private final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		public final String[] nextStringArray() throws IOException {
			return this.br.readLine().split(" ");
		}

		public final Stream<String> nextStream() throws IOException {
			return Arrays.stream(this.nextStringArray());
		}

		public final IntStream nextIntStream() throws NumberFormatException, IOException {
			return this.nextStream().mapToInt(Integer::parseInt);
		}

		public final int[] nextIntArray() throws IOException {
			return this.nextIntStream().toArray();
		}

		public final int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(nextLine());
		}

		public final int nextInt(int radix) throws NumberFormatException, IOException {
			return Integer.parseInt(nextLine(), radix);
		}

		public final long nextBits() throws NumberFormatException, IOException {
			return Long.parseLong(nextLine().replaceAll(" ", ""), 2);
		}

		public final String nextLine() throws IOException {
			return this.br.readLine();
		}

		@Override
		public final void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 27988