akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <stdio.h>
typedef long long int LL;
#define fr(i,p,n) for(LL i=p;i<n;i++)
#define fr1(i,p,n) for(LL i=p;i>=n;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define PI 3.14159265358979323846
#define MOD 1000000007
#define MOD1 998244353
#define INF 1e18
#define precise cout << std::setprecision(10) << std::fixed;

using namespace std;
 
int D;
vector<int> N;
#define MOD 1000000007


void input() {
  string n;
  cin >> n >> D;

  for (auto x: n) {
    N.push_back(x - '0');
  }
}
int dp[10002][2][101];


int solveRec(vector<int> &digits, int k = 0, bool tight = true, int sum = 0) {
  // 整数文字列の最後まで到達
  if (k == digits.size()) {
    return sum % D == 0;
  }
  int x = digits.at(k);
  int r = tight ? x : 9; // その桁において最大の場合は次の桁で制限がかかる

  int res = dp[k][tight][sum];
  if (~res) return res; // DP
  res = 0;
  for (int i=0; i<=r; i++) {
    res += solveRec(digits, k + 1, tight && i == r, (sum + i) % D);
    res %= MOD;
  }
  dp[k][tight][sum] = res;
  return res;
}


void solve() {
  memset(dp, -1, sizeof(dp));
  int total = solveRec(N);
  total = (total - 1) % MOD; // remove 0
  if (total < 0) total += MOD;
  cout << total << endl;
}


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

Measured memory_bytes: 12468
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main(){
  long long n, k;
  cin >> n >> k;
  long long x[n];
  for (int i = 0; i < n; i++)
    cin >> x[i];
  long long count;
  count = x[n - 1] - x[0] + max(abs(x[n - 1]), abs(x[0]));
  for (int i = 0; i < n - k + 1; i++){
    long long tmp_count = x[i + k - 1] - x[i] + min(abs(x[i]), abs(x[i + k - 1]));
    if (tmp_count < count)
      count = tmp_count;
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int gcd(int a,int b);
int main(void){
    int n;
    int a,b,c;
    int tmp1,tmp2;
    int ret = 0;
    scanf("%d",&n);
    for ( a = 1 ; a <= n ; a++){
        for ( b = 1 ; b <= n ; b++){
            for ( c = 1 ; c <= n ; c++){
                tmp1 = gcd(a,b);
                tmp2 = gcd(c,tmp1);
                ret = ret + tmp2;
            }
        }
    }

    printf("%d\n",ret);
}
int gcd(int a,int b){
    int c;
    int tmp;
    if(b > a){  //bがaより大きい場合bとaを入れ替える
        c = a;
        a = b;
        b = c;
    }
    tmp = a % b;
    while(tmp!=0){
        a = b;
        b = tmp;
        tmp = a % b;
    }
    return b;
}


Measured memory_bytes: 1708
#pragma GCC optimize("O3")

#include <bits/stdc++.h>

using namespace std;

#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr)
#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(n) FOR(O, 1, (n))
#define pb push_back
#define f first
#define s second
typedef long double ld;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<ll> vl;
typedef vector<piii> viii;

const int MAXN = 1000100, MAXK = 23;
const ll MOD =  2020202003;
const ll INF = 1e18;
const ld PI = asin(1) * 2;

void setIO () {
    FAST_IO;
}

void setIO (string s) {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
	freopen((s+".out").c_str(),"w",stdout);
}




int main() {
	setIO();

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    while (true) {
        c -= b;
        if (c <= 0) {cout << "Yes"; break;}
        a -= d;
        if (a <= 0) {cout << "No"; break;}
    }

	return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

int main(){
    string s;
    int m;
    cin >> s >> m;
    rep(i, m) {
        string x;
        int a, b;
        cin >> x >> a >> b;
        if(x == "print") cout << s.substr(a, b-a+1) << endl;
        else if(x == "replace") {
            string q;
            cin >> q;
            s.replace(a, b-a+1, q);
        }
        else {
            reverse(s.begin()+a, s.begin()+b+1);
        }
    }

    return 0;
}


Measured memory_bytes: 3232
def solve(n,x):
	ans = 0
	for i in range(1,n-1):
		for j in range(i+1, n):
			k = x-i-j
			if k>j and k<=n:
				ans += 1
	return ans

while True:
	n,x = map(int, input().split())
	if n==0 and x==0:
		break
	print(solve(n,x))



Measured memory_bytes: 5600
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

using P = pair<int, int>;

bool check(const vector<int>& A, int m) {
  vector<P> ps;
  for (int i = 1; i < A.size(); i++) {
    if (A[i - 1] < A[i]) {
      continue;
    }
    while (!ps.empty() && A[i] < ps.back().fst) {
      ps.pop_back();
    }
    int y = A[i];
    for (; y > 0; y--) {
      if (ps.empty() || ps.back().fst < y) {
        ps.emplace_back(y, 2);
        break;
      }
      if (ps.back().fst == y && ps.back().snd < m) {
        ++ps.back().snd;
        break;
      }
      ps.pop_back();
    }
    if (y <= 0) return false;
  }
  return true;
}

int main() {
  int N;
  while (cin >> N) {
    vector<int> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    bool up = true;
    for (int i = 1; i < N; i++) up &= A[i - 1] < A[i];
    if (up) {
      cout << 1 << endl;
      continue;
    }
    int ng = 1, ok = 200010;
    while (ok - ng > 1) {
      int m = (ng + ok) / 2;
      if (check(A, m)) {
        ok = m;
      } else {
        ng = m;
      }
    }
    cout << ok << endl;
  }
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main()
{
  string s;
  cin >> s;
  int n=s.size();
  int sum=0;
  string z="0";
  string t;
  int res;
  for(int i=0;i<n;i++){
    t=s.substr(i,1);
    if(z.compare(t)==0) sum++;
  }
  if(sum*2>n) res=2*(n-sum);
  else res=2*sum;
  cout << res << endl;
  return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if ((A + B) > (C + D)) {
    cout << "Left" << endl;
  }
  else if ((A + B) < (C + D)) {
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
} 

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] rate = new int[8];
		int hi = 0;
		for (int i = 0; i < N; i++) {
			int col = sc.nextInt();
			if (col < 400) {
				rate[0]++;
			} else if (col < 800) {
				rate[1]++;
			} else if (col < 1200) {
				rate[2]++;
			} else if (col < 1600) {
				rate[3]++;
			} else if (col < 2000) {
				rate[4]++;
			} else if (col < 2400) {
				rate[5]++;
			} else if (col < 2800) {
				rate[6]++;
			} else if (col < 3200) {
				rate[7]++;
			} else {
				hi++;
			}
		}
		int min = 0;
		for (int i : rate) {
			if (i != 0) {
				min++;
			}
		}
		if (hi != 0 && min == 0) {
			System.out.println(1 + " " + hi);
		} else {
			int max = min + hi;
			System.out.println(min + " " + max);
		}
	}
}

Measured memory_bytes: 21972
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};

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



int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  // cout << fixed << setprecision(15);

  ll N; cin>>N;
  vector<vector<pair<ll,ll>>> graph(N,vector<pair<ll,ll>>(0));
  rep(i,N-1){
    ll a,b,c; cin>>a>>b>>c; a--; b--;
    graph.at(a).push_back({b,c});
    graph.at(b).push_back({a,c});
  }
  
  ll Q,K; cin>>Q>>K; K--;
  vector<ll> vec(N,INF);
  queue<ll> que;
  vec[K]=0;
  que.push(K);
  while(!que.empty()){
    ll v=que.front(); que.pop();
    for(auto p:graph.at(v)){
      ll cost,nv; tie(nv,cost)=p;
      if(vec[nv]<INF) continue;
      vec[nv]=vec[v]+cost;
      que.push(nv);
    }
  }
  
  rep(i,Q){
    ll x,y; cin>>x>>y; x--; y--;
    cout<<vec[x]+vec[y]<<endl;
  }
  
  return 0;
}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
inline string numstr(int m){str s="";while(m>0){char c;int a=m/10;if(a>0)a=m%(a*10);else a=m;c=(char)('0'+a);s+=c;m/=10;}str st="";for(int i=s.size()-1;i>=0;i--){st+=s[i];}return st;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;
int dp[50][3003];
///?£????????£???????????§???????????????????£??????§???????????£???(???????°????????????¨???????¶?...)(?????????????????§???.)
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s;
    int mod=100000;
    while(1){
    cin >> n >> m >> s;
    if(n==0&&m==0&&s==0)break;
    rep(i,0,50){
        rep(j,0,3003){
            dp[i][j]=0;
        }
    }
    dp[0][0]=1;
    rep(i,1,m+1){
        for(int j=n*n;j>0;j--){
            rep(k,i,s+1){
                (dp[j][k]+=dp[j-1][k-i])%=mod;
            }
        }
    }
        cout << dp[n*n][s]%mod << endl;
    }
    return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=2e5+5;
int a[M];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    int m=a[1];
    ll cnt=0;
    for(int i=1;i<=n;i++)
    {
        if(a[i]<m)
        {
            cnt+=m-a[i];
        }
        m=max(a[i],m);
    }
    printf("%lld\n",cnt);
    return 0;
}


Measured memory_bytes: 4608
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
#include <limits.h>
#define swap(type,a,b) do{type t=a;a=b;b=t;}while(0);
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define ll long long
#define INF 100000000
#define MOD 1000000007
#define SIZE 100005
#define FOR(i,a,n) for(i=(a);i<(n);i++)
int comp(const void* a,const void* b){
	return *(int*)a-*(int*)b;
}
int a[200000];
int b[200001];
int cnt[200001];
int main(void)
{
	int n,m,sum=0,x,y,t1,t2,i,j;
	scanf("%d%d",&n,&m);
	FOR(i,0,n){
		scanf("%d",&a[i]);
		cnt[a[i]]++;
	}
	FOR(i,1,n+1){
		b[MAX(0,i-cnt[i])]++;
		b[i]--;
	}
	FOR(i,1,n) b[i]+=b[i-1];
	FOR(i,0,n) sum+=(b[i]==0);
	//FOR(i,0,n) printf("%d ",b[i]);
	FOR(i,0,m){
		scanf("%d %d",&x,&y);
		x--;
		t1=a[x]-cnt[a[x]];
		if(t1>=0&&--b[t1]==0) sum++;
		cnt[a[x]]--;
		
		t2=y-cnt[y]-1;
		if(t2>=0&&++b[t2]==1) sum--;
		cnt[y]++;
		
		printf("%d\n",sum);
		a[x]=y;
	}
	return 0;
}


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

int n;
int a[110];
inline char legal(const int &x, const int &y, const int &z);

int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; ++i)
		scanf("%d", &a[i]);
	int ans = 0;
	for (int i = 0; i < n - 2; ++i)
		for (int j = i + 1; j < n - 1; ++j)
			for (int k = j + 1; k < n; ++k)
				ans += legal(a[i], a[j], a[k]);
	printf("%d\n", ans);
	return 0;
}

inline char legal(const int &x, const int &y, const int &z) {
	return x + y > z && y + z > x && z + x > y && x != y && y != z && z != x;
}



Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  int i;
  string s,t;
  cin>>n>>s;
  if(n%2!=0)cout<<"No"<<endl;
  if(n%2==0){
  for(i=0;i<n/2;i++) t+=s.at(i);
  if(s==t+t)cout<<"Yes"<<endl;
  else if(s!=t+t)cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
 
int main() {
  int64_t x;
  cin >> x;
  int64_t s = 100;
  rep (i,3761) {
    s  = s * 1.01;
    if (s >= x) {
    cout << i + 1 << endl;
      break;
    }
    
  }
    }

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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  string s ;
  cin >> s ;
  
  if(s.at(0)==s.at(1) && s.at(1)==s.at(2)){
    cout <<"Yes"<<endl ;
  }
  else if(s.at(1)==s.at(2) && s.at(2)==s.at(3)){
    cout <<"Yes"<<endl ;
  }
  else{
    cout <<"No"<<endl ;
  }
 
  
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 256
def main():
    # input
    n = int(input())

    li = []
    for i in range(n):
        a = int(input())
        dic = {}
        for j in range(a):
            x, y = map(int, input().split())
            dic[x] = y
        li.append(dic)
    # print(li)

    # calc
    ans = 0
    flag = False
    for num in range(1, 2**n):
        num = bin(num)[2:].rjust(n, '0')
        for i in range(len(li)):
            if num[i] == '1':
                for j, key in enumerate(li[i]):
                    if num[key-1] != str(li[i][key]):
                        flag = True
                        break
                if flag:
                    flag = False
                    break
        else:
            # print(num, ans)
            ans = max(num.count('1'), ans)
    print(ans)




if __name__ == '__main__':
    main()


Measured memory_bytes: 48236
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int n;
  cin >> n;
  if (n <= 999) cout << "ABC" << endl;
  else cout << "ABD" << endl;
}

Measured memory_bytes: 256
s = input()
l = len(s)
n = [int(x) for x in s]
max_v = max(sum(n), n[0]-1 + 9*(l-1))
for i in range(1,l):
    max_v = max(max_v, sum(n[:i-1]) + n[i]-1 + 9*(l-1-i))
print(max_v)

Measured memory_bytes: 3060
#include <algorithm>
#include <climits>
#include <cmath>
#include <csignal>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

using ll = long long;
using namespace std;

int main() {
    string s = "";
    cin >> s;
    int ans = 100000;
    for (int i=0; i<26; i++) {
        char now = 'a' + i;
        int maxi = 0, buf = 0;
        for (char c : s) {
            if (c == now) {
                maxi = max(maxi, buf);
                buf = 0;
            }
            else {
                buf++;
            }
        }
        maxi = max(maxi, buf);
        ans = min(ans, maxi);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
def calc(N, A):
    d = {i + 1: 0 for i in range(N)}
    for a in A:
        d[a] += 1
    return '\n'.join([str(d[k]) for k in d])


N = int(input())
A = [int(s) for s in input().split()]
print(calc(N, A))

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

int main() {
	// your code goes here
	int L,N;
	cin>>N>>L; getchar();
	string s[N];
	for(int i=0;i<N;i++) cin>>s[i];
	sort(s,s+N);
	for(int i=0;i<N;i++) cout<<s[i];
	return 0;
}

Measured memory_bytes: 256
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>
#include <cmath>
#include <sstream>

using namespace std;

int main()
{
	while (true)
	{
		int A, B;
		int numP[20][3] = {};
		int indP[20] = {};
		int numQ[20][3] = {};
		{
			std::string tmp;
			getline(cin, tmp);
			stringstream(tmp) >> A >> B;
		}

		if (A==0 && B==0) {
			break;
		}

		for (int i = 0; i < A; ++i) {
			string tmp;
			getline(cin, tmp);

			numP[i + 1][0] = numP[i][0];
			numP[i + 1][1] = numP[i][1];
			numP[i + 1][2] = numP[i][2];
			indP[i] = 0;
			int j = 0;
			for (; j < tmp.size() && tmp[j] == '.'; j++)
			{
				++indP[i];
			}
			for (; j < tmp.size(); j++)
			{
				if (tmp[j] == '(') {
					++numP[i+1][0];
				}
				else if (tmp[j] == ')') {
					--numP[i + 1][0];
				}
				else if (tmp[j] == '[') {
					++numP[i + 1][1];
				}
				else if (tmp[j] == ']') {
					--numP[i + 1][1];
				}
				else if (tmp[j] == '{') {
					++numP[i + 1][2];
				}
				else if (tmp[j] == '}') {
					--numP[i + 1][2];
				}
			}
		}
		for (int i = 0; i < B; ++i) {
			string tmp;
			getline(cin, tmp);

			numQ[i + 1][0] = numQ[i][0];
			numQ[i + 1][1] = numQ[i][1];
			numQ[i + 1][2] = numQ[i][2];
			int j = 0;
			for (; j < tmp.size(); j++)
			{
				if (tmp[j] == '(') {
					++numQ[i + 1][0];
				}
				else if (tmp[j] == ')') {
					--numQ[i + 1][0];
				}
				else if (tmp[j] == '[') {
					++numQ[i + 1][1];
				}
				else if (tmp[j] == ']') {
					--numQ[i + 1][1];
				}
				else if (tmp[j] == '{') {
					++numQ[i + 1][2];
				}
				else if (tmp[j] == '}') {
					--numQ[i + 1][2];
				}
			}
		}
		

		int res[20] = {};
		for (int a = 0; a < 20; a++) {
			res[a] = -2;
		}

		for (int a = 1; a <= 20; a++)
			for (int b = 1; b <= 20; b++)
				for (int c = 1; c <= 20; c++)
		{
			bool bok = true;
			for (int i = 0; i < A; ++i) {
				int indent = numP[i][0] * a + numP[i][1] * b + numP[i][2] * c;
				bok &= (indent == indP[i]);
			}

			if (!bok) {
				continue;
			}


			for (int i = 0; i < B; i++)
			{
				int indent = numQ[i][0] * a + numQ[i][1] * b + numQ[i][2] * c;
				if (res[i] == -2 || indent == res[i]) {
					res[i] = indent;
				}
				else {
					res[i] = -1;
				}
			}

		}

		for (int i = 0; i < B; i++)
		{
			if (res[i] == -2) { res[i] = -1; }
			cout << res[i] << (i==B-1?'\n': ' ');
		}


	whilecontinue:;
	}
}
#endif



Measured memory_bytes: 3136
DList = Struct.new :x, :p, :n
gets.to_i.times do
  initial, *xs = gets.scan(/[a-z]|->|<-/)
  l = DList.new initial
  xs.each_slice(2) do |c, x|
    if c == '<-'
      unless l.p
        l.p = DList.new x
        l.p.n = l
      end
      l = l.p
    else
      unless l.n
        l.n = DList.new x
        l.n.p = l
      end
      l = l.n
    end
  end
  l = l.p while l.p
  while l
    print l.x
    l = l.n
  end
  puts
end

Measured memory_bytes: 8988
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    n, m = map(int, input().split()) # 頂点の数、辺の数
    edge = [[] * n for i in range(n)] # rangeに頂点の数。繋がっている頂点を投入するリスト
    for i in range(m): # rangeに辺の数
        x, y = map(int, input().split())
        x, y = x - 1, y - 1
        edge[x].append(y)
        edge[y].append(x) # 有向ならコメントアウト
    for i in range(n):
        print(len(edge[i]))
resolve()

Measured memory_bytes: 3188
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	public static void main(String args[]) {
		FastScanner scanner = new FastScanner();
		int n=scanner.nextInt();
		int r=scanner.nextInt();
		int ans=(n>=10)?r:r+100*(10-n);
		System.out.println(ans);
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define pb push_back
#define pr pair<int,int>
using namespace std;
using ll = long long;
// using mod = 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	int t; cin >> t;

	int h,m,s;

	h = t/3600;
	t -= h*3600;
	m = t/60;
	t -= m*60;
	s = t;
	// string ans = to_string(h) + ":" to_string(m) + ":" + to_string(s);

	cout << h << ":" << m << ":" << s  << endl;

	return 0;
}



Measured memory_bytes: 3104
program proba
	implicit none
	integer :: x, y
    integer :: ans
    
    read(*,*) x,y
    
    ans = 0
    if(x == 1 .and. y == 1) then
    	ans = 1000000
	else
    	ans = max(4-x, 0) * 100000 + max(4-y, 0) * 100000
    end if
    
    write(*,*) ans
    stop
end program proba

Measured memory_bytes: 256
def MI():  return map(int, input().split())
N,Q=MI()
graph=[[] for i in range(N)]
for i in range(1,N):
  a,b=MI()
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
point=[0]*N  
for i in range(Q):
  p,x=MI()
  point[p-1]+=x
import collections
q=collections.deque()
q.append(0)
check=[0]*N
check[0]=1
while len(q)>0:
  v=q.pop()
  check[v]=1
  for u in graph[v]:
    if check[u]==1:
      continue
    point[u]+=point[v]
    q.append(u)
print(*point)

Measured memory_bytes: 56816
/*
#include<bits/stdc++.h>
using namespace std;
int main()
{
   int a,b;
   cin>>a>>b;
   char c1=a+'0';
   char c2=b+'0';

   string s1(b,c1),s2(a,c2);
   cout<<min(s1,s2)<<endl;
   exit(0);
}
*/

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;

    for(int i=0;i<max(a,b);i++)
    {
        cout<<min(a,b);
    }

    cout<<endl;
    exit(0);
}


Measured memory_bytes: 3640
#include<iostream>

using namespace std;

class Dice {
    public:
        int D1;
        int D2;
        int D3;
        int D4;
        int D5;
        int D6;

        Dice(int d1, int d2, int d3, int d4, int d5, int d6);
        void Rotate_E();
        void Rotate_N();
        void Rotate_S();
        void Rotate_W();

};

Dice::Dice(int d1, int d2, int d3, int d4, int d5, int d6) {
    D1 = d1;
    D2 = d2;
    D3 = d3;
    D4 = d4;
    D5 = d5;
    D6 = d6;
}

void Dice::Rotate_E() {
    int tmp;

    tmp = D3;
    D3 = D1;
    D1 = D4;
    D4 = D6;
    D6 = tmp;
}

void Dice::Rotate_N() {
    int tmp;

    tmp = D5;
    D5 = D1;
    D1 = D2;
    D2 = D6;
    D6 = tmp;
}

void Dice::Rotate_S() {
    int tmp;

    tmp = D5;
    D5 = D6;
    D6 = D2;
    D2 = D1;
    D1 = tmp;
}

void Dice::Rotate_W() {
    int tmp;

    tmp = D3;
    D3 = D6;
    D6 = D4;
    D4 = D1;
    D1 = tmp;
}

int main () {

    int d1, d2, d3, d4, d5, d6;
    cin >> d1 >> d2 >> d3 >> d4 >> d5 >> d6;
    Dice Dice1(d1, d2, d3, d4, d5, d6);

    int q;
    cin >> q;

    for (int i = 0; i < q; i++) {
        int a, b;
        cin >> a >> b;

        if (Dice1.D3 == b || Dice1.D4 == b) {
            Dice1.Rotate_E();
        }

        while (Dice1.D2 != b) {
            // cout << "Now Loading\n" << endl;
            Dice1.Rotate_N();
        }

        while (Dice1.D1 != a) {
            // cout << "Now Loading2\n" << endl;
            Dice1.Rotate_E();
        }

        cout << Dice1.D3 << endl;
    }

    return 0;
}


Measured memory_bytes: 3084
import math

a,b,x = map(int,input().split())

s = x / a
t = s / a

if t * 2 > b:

    print (math.degrees(math.atan((b-t)/(a*0.5))))

else:

    tei = s * 2 / b

    print (math.degrees(math.atan(b / tei)))


Measured memory_bytes: 38384
use proconio::{fastout, input};

struct UnionFind {
    set: Vec<i64>,
}

impl UnionFind {
    fn new(n: usize) -> Self {
        let set: Vec<i64> = vec![-1; n];
        Self { set }
    }

    fn root(&mut self, i: usize) -> usize {
        if self.set[i] < 0 {
            i
        } else {
            self.set[i] = self.root(self.set[i] as usize) as i64;
            self.set[i] as usize
        }
    }

    fn unite(&mut self, x: usize, y: usize) -> bool {
        let mut x_root = self.root(x);
        let mut y_root = self.root(y);
        if x_root == y_root {
            false
        } else {
            if self.set[x_root] > self.set[y_root] {
                std::mem::swap(&mut x_root, &mut y_root);
            }
            self.set[x_root] += self.set[y_root];
            self.set[y_root] = x_root as i64;
            true
        }
    }

    fn size(&mut self, i: usize) -> usize {
        let par = self.root(i);
        (self.set[par] * -1) as usize
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        a_b_vec: [(usize, usize); m],
    };
    let a_b_vec: Vec<(usize, usize)> = a_b_vec.iter().map(|(a, b)| (a - 1, b - 1)).collect();
    let mut set: UnionFind = UnionFind::new(n);
    for a_b in a_b_vec.iter() {
        set.unite(a_b.0, a_b.1);
    }
    let mut ans = 0;
    for i in 0..n {
        ans = ans.max(set.size(i));
    }
    println!("{}", ans);
}


Measured memory_bytes: 12360
import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
    public static void main (String[] args) throws Exception {
        Scanner sch = new Scanner(System.in);
        int q = sch.nextInt();
       

        int[] B = countingpaixu(q,sch);
         StringBuilder af = new StringBuilder("");
        af.append(B[0]);
        for (int i = 1; i < B.length; ++i) {
            af.append(" ").append(B[i]);
        
        }
        
        System.out.println(af);
    }

    public static int[] countingpaixu(int n,Scanner aj) {
         int k = 0;
         int[] A = new int[n];
        
        for (int i = 0; i < n; i++) {
            A[i] = aj.nextInt();
            if (A[i] > k) {
                k = A[i];
            }
        }
        int[] P = new int[A.length];
        int i;
        int[] C = new int[k + 1];
        
        for (i = 0; i < A.length; i++) {
            C[A[i]]++;
        }
        for (i = 1; i <= k; ++i) {
            C[i] += C[i - 1];
        }
        for (i = A.length - 1; i >= 0; i--) {
            P[C[A[i]] - 1] = A[i];
            C[A[i]]--;
        }
        return P;
    }
}


Measured memory_bytes: 508812
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n,m;
  cin >> n >> m;
  vi s[m];
  rep(i,m){
    int K;
    cin >> K;
    rep(j,K){
      int t;
      cin >> t;
      t--;
      s[i].push_back(t);
    }
  }
  vi p(m);
  rep(i,m)cin >> p[i];
  int ans = 0;;
  rep(i,2<<(n-1)){
    int cnt2 = 0;
    bitset<10> b(i);
    rep(k,m){
      int cnt =0;
      for(auto swi:s[k]){
        cnt += b[swi];
      }
      if(cnt%2 == p[k]) cnt2++;
    }
    if(cnt2 == m) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3", "unroll-loops")
#pragma GCC target("avx2")

#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <sstream>
#include <deque>
#include <queue>
#include <complex>
#include <random>
#include <cassert>
#include <chrono>

using namespace std;

#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define FIXED cout << fixed << setprecision(12)
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define graph vector<vector<int>>
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define f first
#define s second
#define hashmap unordered_map
#define hashset unordered_set
#define eps 1e-9
#define mod 1000000007
#define inf 3000000000000000007ll
#define sz(a) signed(a.size())
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

#ifdef DEBUG
    mt19937 gen(857204);
#else
    mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

template<class T, class U> inline void checkmin(T &x, U y) { if (y < x) x = y; }
template<class T, class U> inline void checkmax(T &x, U y) { if (y > x) x = y; }
template<class T, class U> inline bool ifmax(T &x, U y) { if (y > x) return x = y, true; return false; }
template<class T, class U> inline bool ifmin(T &x, U y) { if (y < x) return x = y, true; return false; }
template<class T> inline void sort(T &a) { sort(all(a)); }
template<class T> inline void rsort(T &a) { sort(rall(a)); }
template<class T> inline void reverse(T &a) { reverse(all(a)); }
template<class T, class U> inline istream& operator>>(istream& str, pair<T, U> &p) { return str >> p.f >> p.s; }
template<class T> inline istream& operator>>(istream& str, vector<T> &a) { for (auto &i : a) str >> i; return str; }
template<class T> inline T sorted(T a) { sort(a); return a; }

signed main() {
    FAST; FIXED;
    ll h, w;
    cin >> h >> w;
    if (h > w) swap(h, w);
    if (h == 1) {
        cout << 1;
        return 0;
    }
    cout << (h * w + 1) / 2;
    #ifdef DEBUG
        cerr << "Runtime is: " << clock() * 1.0 / CLOCKS_PER_SEC << endl;
    #endif
    return 0;
}

Measured memory_bytes: 256
/* be name khoda */

// #define stream_enable
#define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
using namespace std;

#ifdef stream_enable
#define cin sss
#endif
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif

typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;

const ll MOD = 1000000007;
const long long BIG = 1446803456761533460;
const int Big = 336860180;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()

#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debugp(x) cout << #x << " -> " << "(" << (x).F << ", " << (x).S << ")" << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugap(x, n) cout << #x << " ->\n"; fori (i1_dap, n) { cout << "(" << (x)[i1_dap].F << ", " << (x)[i1_dap].S << ")\n"; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
#define debugav(x, n) cout << #x << " ->\n"; fori (i1_dav, n) { fori (i2_dav, (x)[i1_dav].size()) { cout << (x)[i1_dav][i2_dav] << ' '; } cout << '\n'; } cout << endl
#define debugia(x, n) cout << #x << " ->\n"; fori (i1_dia, n) { cout << i1_dia << " : " << (x)[i1_dia] << '\n'; } cout << endl

#define forifrom(i, s, n) for(ll i = (s); i < (n); ++i)
#define forirto(i, n, e) for(ll i = (n) - 1; i >= (e); --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)

#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))

#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD

stringstream sss;

// -----------------------------------------------------------------------

const ll maxn = 100010;

ll n, A[maxn], ps[maxn];

void MAIN() {

    cin >> n;
    fori (i, n) cin >> A[i];
    sort(A, A + n);
    fori (i, n) ps[i + 1] = ps[i] + A[i];
    ll ans = 1;
    while (ps[n - ans] * 2 >= A[n - ans]) ++ans;
    cout << ans << '\n';

}

// -----------------------------------------------------------------------

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    cout << fixed << setprecision(10);
    sss << R"(

    )";
    MAIN();
    return 0;
}



Measured memory_bytes: 1792
var
 k:ansistring;
 i,w,n,e,s:longint;
begin
 read(k);
 for i:=1 to length(k) do
  begin
   if k[i]='W' then w:=1;
   if k[i]='N' then n:=1;
   if k[i]='E' then e:=1;
   if k[i]='S' then s:=1;
  end;
 if (((w=1) and (e=1)) and ((n=0) and (s=0))) or
    (((w=1) and (e=1)) and ((n=1) and (s=1))) or
    (((w=0) and (e=0)) and ((n=1) and (s=1))) or
    (((w=0) and (e=0)) and ((n=0) and (s=0))) then writeln('Yes')
                                              else writeln('No');
end.

Measured memory_bytes: 128
N = int(input())
A = list(map(int,input().split()))
min = 1000000000
max = 0
for i, a in enumerate(A):
    if i == 0:
        max = a
        min = a

    if a > max:
        max = a
    elif a < min:
        min = a
print(max - min)
    

Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
using namespace std;

int main()
{
    string c;
    cin >> c;
    
    if (c == "ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
}


Measured memory_bytes: 3624
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class Main{
	
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		
		// input
		final int NUM = scan.nextInt();
		List<Integer> powers = new ArrayList<>();
		for(int i = 0; i < NUM*3; i++){
			powers.add(Integer.parseInt(scan.next()));
		}
		
		// sort
		Collections.sort(powers, Comparator.reverseOrder());

		// search
		long sum = 0;
		int count = 0;
		for(int i = 1; count < NUM; i += 2){
			sum += powers.get(i);
			count++;
		}
		
		// answer
		System.out.println(sum);
		
	}
}

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

int main(){

int a, b;
char op;

for(;;){
cin >> a >> op >> b;

if(op == '+'){cout << a + b << endl;}
else if(op == '-') {cout << a - b << endl;}
else if(op == '*') {cout << a * b << endl;}
else if(op == '/') {cout << a / b << endl;}
else break;
 }
}



Measured memory_bytes: 3104
#include <iostream>
#include <math.h>
#include <iomanip>

int main() {
  long double A, B, H, M, arg_H, arg_M, arg, l;
  std::cin >> A >> B >> H >> M;
  arg_H = H * 30 + M/60 * 30;
  arg_M = M * 6;
  arg = std::abs(arg_H - arg_M);
  l = sqrt((A*A + B*B - 2*A*B*cos(arg/180*M_PI)));
  std::cout << std::setprecision(10) << l << std::endl;
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll a, sum;
string s, t;
map< char, vector<int> >mp;
int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> s >> t;
    for(int i = 1;i <= s.size();++i)
        mp[s[i - 1]].push_back(i);
    for(auto it : t)
    {
        if(mp[it].empty())  return cout << -1, 0;
        auto is = upper_bound(mp[it].begin(), mp[it].end(), a);
        if(is == mp[it].end())
            sum += s.size() - a, a = 0, is = mp[it].begin();
        sum += *is - a, a = *is;
    }
    cout << sum;
    return 0;
}


Measured memory_bytes: 1228
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <functional>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int m,n;
    cin>>m>>n;
    while(m){
    bool year[7368792]={false};
    rep(i,n){
        int t = m+i;
        if(year[t]==false){
            // cout<<t<<endl;
            for(int j = t;j<=7368792;j+=t){
                year[j]=true;
            }
        }else n++;
        
    }
    int ans = 0;
    rep(i, 7368792){
        // cout<<year[i];
        if(year[i]==true&&year[i+1]==false){
            ans = i+1;
            break;
        }
    }
    cout<<ans<<endl;
    cin>>m>>n;
    }

    return 0;
}


Measured memory_bytes: 10200
#include <cstdio>
using namespace std;

int main(){
	int a, b, n;
	while(scanf("%d%d%d", &a, &b, &n) == 3){
		a %= b;
		int s = 0;
		for(int i = 0; i < n; ++i){
			a *= 10;
			s += a / b;
			a %= b;
		}
		printf("%d\n", s);
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
#define SP << " " <<
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "NO" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  998244353
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll H,W; cin>>H>>W;
    ll c[H][W];
    rep(i,H){
        rep(j,W){
            char cc; cin>>cc;
            c[i][j]=cc-'a';
        }
    }
    ll ans=0;
    // i個1->H落としてこする。0->i)から、左右をH-i回（i個落ち,i-1こ落ち)
    rep(h,W-1){
        ll dp[310][310]={};
        ll dpx[310][310]={};
        rep(i,305) rep(j,305) dp[i][j]=INF2;
        dp[H][H]=0;
        reps(i,1,H+1){
            reps(j,1,H+1){
                dpx[i][j]=dpx[i-1][j-1]+(c[i-1][h]==c[j-1][h+1]);
            }
        }
        repr(i,H,0){
            repr(j,H,0){
                if(i>0) mini(dp[i-1][j],dp[i][j]+dpx[i][j]);
                if(j>0) mini(dp[i][j-1],dp[i][j]+dpx[i][j]);
            }
        }
        ans+=dp[0][0];
    }
    cout<< ans <<"\n";


}

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


Measured memory_bytes: 2432
num = int(input())
ans = 0
cnt = 0
for x in range(num):
    d1, d2 = map(int, input().split())
    if d1 == d2: cnt += 1
    else: 
        ans = max(cnt, ans)
        cnt = 0
ans = max(cnt, ans)
if ans >= 3: print("Yes")
else:  print("No")

Measured memory_bytes: 9184
using System;
using System.Globalization;
using System.IO.Pipes;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int H, W;
            H = int.Parse(str[0]);
            W = int.Parse(str[1]);
            string[] STR = Console.ReadLine().Split(' ');
            int h, w;
            h=int.Parse(STR[0]);
            w = int.Parse(STR[1]);

            Console.WriteLine(H * W - H * w - h * W + h * w);
        }

    }
}


Measured memory_bytes: 27488
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
#define pb push_back
using namespace std;

typedef long long LL;
typedef vector<int> vi;

const int N = 100010;

int n, m;
int outdeg[N];
vi G[N];
int f[N];
int vis[N];

int dfs(int u) {
	if(vis[u] != 0) {
		return f[u];
	}
	if(G[u].size() == 0) {
		return (f[u] = 0);
	}
	int best = 0;
	for(int par: G[u]) {
		best = max(best, 1 + dfs(par));
	}
	vis[u] = 1;
	return (f[u] = best);
}

int main() {
	memset(vis, 0, sizeof(vis));
	memset(outdeg, 0, sizeof(outdeg));
	memset(f, 0, sizeof(f));
	cin >> n >> m;
	for(int _ = 0 ; _ < m ; _++) {
		int u, v; cin >> u >> v;
		u--, v--;
		outdeg[u]++;
		G[v].pb(u);
	}

	int ans = 0;
	for(int i = 0 ; i < n ; i++) {
		if(outdeg[i] == 0) {
			ans = max(ans, dfs(i));
		}
	}
	cout << ans;
}


Measured memory_bytes: 11520
#include <iostream>
#include <vector>

using namespace std;

bool is_fair(vector<int> &s) {
	bool one = false, two = false, three = false;
	for(auto &&x: s) {
		if(x == 1) one = true;
		if(x == 2) two = true;
		if(x == 3) three = true;
	}
	return one && two && three;
}

bool is_zero(vector<int> &s) {
	bool y = true;
	for(auto &&x: s) {
		if(x != 0) y = false;
	}
	return y;
}

int calc_cost(int A, int B, int C, vector<int> &s, vector<int> &v) {
	int aa = 0, bb = 0, cc = 0;
	int ac = 0, bc = 0, cs = 0;

	for(int i = 0; i < s.size(); i++) {
		switch(s[i]) {
		case 1:
			if(aa > 0) ac += 10;
			aa += v[i];
			break;
		case 2:
			if(bb > 0) bc += 10;
			bb += v[i];
			break;
		case 3:
			if(cc > 0) cs += 10;
			cc += v[i];
			break;
		}
	}
	ac += abs(A - aa);
	bc += abs(B - bb);
	cs += abs(C - cc);
	return ac + bc + cs;
}


int main() {
	int N, A, B, C;
	cin >> N >> A >> B >> C;

	vector<int> v(N);

	for(auto &x: v) cin >> x;

	vector<int> s(N, 0);

	int min_cost = 1145141919;
	s[0] = 1;
	while(is_zero(s) == false) {
	if(is_fair(s)) {
		min_cost = min(min_cost, calc_cost(A, B, C, s, v));
	}

	s[0] += 1;
	for(int i = 0; i < N; i++) {
		if(s[i] == 4) {
			s[i] = 0;
			if(i + 1 < N)
				s[i + 1] += 1;
		}
	}
	}

	cout << min_cost << endl;
}


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

int main() {
  string s;
  cin >> s;
  int n = s.length() / 2;
  int count = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] != s[s.length() - 1 - i]) ++count;
  }
  cout << count << endl;
}


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

template <typename T> void debug(T t) { cout<<t<<endl; }
template<typename T, typename... Args> void debug(T t, Args... args) { cout<<t<<" "; debug(args...); }

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define int long long
#define double long double

int n;
int storemore[200006]={};
int storeless[200007]={};
int power(int x,int y,int p)
{ 
    int res = 1;      
    x = x % p;  
    while (y > 0) 
    { 
        if((y & 1)==1) 
            res = (res * x) % p; 
        y = y >> 1;  
        x = (x * x) % p;  
    } 
    return res; 
}
int calc(int x)
{
    int ct=0;
    while(x!=0)
        x=(x%__builtin_popcountll(x)),ct++;
    return ct;
}
int32_t main()
{
    IOS;
    int n;
    string s;
    cin>>n>>s;
    int ct=0;
    for(auto i:s)
        ct+=i-'0';
    int orinum1=0,orinum2=0;
    for(int i=n-1;i>=0;i--)
    {
        if(s[i]=='1')
        {
            if(ct>1)
                orinum1=(orinum1+power(2,n-1-i,ct-1))%(ct-1);
            orinum2=(orinum2+power(2,n-1-i,ct+1))%(ct+1);
        }
    }
    for(int i=0;i<n;i++)
    {
        if(s[i]=='0')
        {
            int val=(orinum2+power(2,n-1-i,ct+1))%(ct+1);
            cout<<(1+calc(val))<<endl;
        }
        else
        {
            if(ct-1<=1)
                cout<<ct-1<<endl;
            else
            {
                int val=(orinum1-power(2,n-1-i,ct-1)+3*(ct-1))%(ct-1);
                cout<<(1+calc(val))<<endl;
            }
        }
    }
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
using namespace std;
#define N 505
int n,m;char a[N][N],b[N][N];
int main(){
	scanf("%d%d",&n,&m);
	rep (i,1,n) scanf("%s",a[i]+1),memcpy(b[i],a[i],sizeof(a[i]));
	for (int i=1;i<=n;i+=2) rep (j,2,m-1) a[i][j]='#';
	rep (i,1,n) a[i][1]='#';
	for (int i=2;i<=n;i+=2) rep (j,2,m-1) b[i][j]='#';
	rep (i,1,n) b[i][m]='#';
	rep (i,1,n){rep (j,1,m) putchar(a[i][j]);puts("");}
	puts("");
	rep (i,1,n){rep (j,1,m) putchar(b[i][j]);puts("");}
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
using namespace std;
long long a,b,c,d=0,e[1000001],f[1000001];
int main(){
	cin>>a;
	for(long long i=0;i<a;i++){
		cin>>e[i];
	}
	for(long long i=0;i<a;i++){
		if(e[i]%2==0){
			c=e[i];
	        while(c%2==0){
		        d++;
		        c/=2;
	        }
		}
	}
	cout<<d<<endl;
	return 0;
}

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

int main()
{
	int a,b,c,x,ans=0;
	cin>>a>>b>>c>>x;
	if(500*a+100*b+50*c<x)
	{
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<=a;i++)
		for(int j=0;j<=b;j++)
			for(int k=0;k<=c;k++)
				if(500*i+100*j+50*k==x)
					ans++;
				else
					continue;
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 256