akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<cstdlib>
#include<math.h>
#include<iostream>
using namespace std;

struct st_data{
	double jp;
	int l;
};

int size;
st_data *data;
double xa,ya,xb,yb;
double xs,ys,xt,yt;
int o,l;
double a,b,c;//ax+by+c=0
int n;

int jpn;

//len=|ax+by+c|/sqrt(a^2+b^2)
//point=(x,y)-(ax+by+c)/(a^2+b^2) (a,b)
//joint=(x0,y0)+((x1,y1)-(x0,y0))*len0/(len0+len1)
void set();
double lpp(double,double);
double len(double,double);
double lenn(double,double);
double lenp(double,double);
void point(double*,double*,double,double);
void joint(double*,double*,double,double,double,double,double,double);
void sort();
void swap(st_data*,st_data*);

int main(){
	cin>>size;
	double len0,len1;
	int i;
	double x,y;
	double eps=1.0e-9;
	for(int roop=0;roop<size;roop++){//dataset-roop
		cin>>xa>>ya>>xb>>yb;
		//cout<<"@"<<xa<<"@"<<ya<<"@"<<xb<<"@"<<yb<<endl;
		set();
		cin>>n;
		data=new st_data[n];
		jpn=0;
		for(i=0;i<n;i++){
			cin>>xs>>ys>>xt>>yt>>o>>l;
			len0=len(xs,ys);
			len1=len(xt,yt);
			if(len0*len1>0){
				//cout<<" continue"<<endl;
				continue;
			}
			len0=fabs(len0);
			len1=fabs(len1);
			point(&xs,&ys,xs,ys);
			point(&xt,&yt,xt,yt);
			joint(&x,&y,xs,ys,len0,xt,yt,len1);
			//cout<<" "<<x<<" "<<y<<endl;
			double px0,py0,px1,py1;
			if(xa>xb){
				px0=xb;
				px1=xa;
			}
			else{
				px0=xa;
				px1=xb;
			}
			if(ya>yb){
				py0=yb;
				py1=ya;
			}
			else{
				py0=ya;
				py1=yb;
			}
			if(((px0-x)<=eps && (x-px1)<=eps) && ((py0-y)<=eps && (y-py1)<=eps)){
				if(o==l) data[jpn].l=1;
				else data[jpn].l=0;
				data[jpn++].jp=lpp(x,y);
			}
		}
		sort();
		int p=data[0].l;
		int q=0;
		//cout<<" "<<data[0].jp<<","<<data[0].l<<endl;
		for(i=1;i<jpn;i++){
			//cout<<" "<<data[i].jp<<","<<data[i].l<<endl;
			if(p!=data[i].l){
				p=data[i].l;
				q++;
			}
		}
		cout<<q<<endl;
		delete []data;
	}
	return 0;
}

void set(){
	a=yb-ya;
	b=xa-xb;
	c=xb*ya-xa*yb;
}

double lpp(double x,double y){
	return sqrt((x-xa)*(x-xa)+(y-ya)*(y-ya));
}

double len(double x,double y){
	//len=|ax+by+c|/sqrt(a^2+b^2)
	return ((double)(a*x+b*y+c));
}

double lenn(double x,double y){
	//len=|ax+by+c|/sqrt(a^2+b^2)
	return ((double)(a*x+b*y+c)/sqrt(a*a+b*b));
}

double lenp(double x,double y){
	return ((double)(a*x+b*y+c)/(a*a+b*b));
}

void point(double *x,double *y,double x0,double y0){
	//point=(x,y)-(ax+by+c)/(a^2+b^2) (a,b)
	double l=lenp(x0,y0);
	*x=x0-l*a;
	*y=y0-l*b;
	return;
}

void joint(double *x,double *y,double x0,double y0,double l0,double x1,double y1,double l1){
	//joint=(x0,y0)+((x1,y1)-(x0,y0))*len0/(len0+len1)
	*x=x0+(x1-x0)*l0/(l0+l1);
	*y=y0+(y1-y0)*l0/(l0+l1);
	return;
}

void sort(){
	for(int i=0;i<jpn-1;i++){
		for(int j=0;j<jpn-i-1;j++){
			if(data[j].jp>data[j+1].jp){
				st_data buf=data[j];
				data[j]=data[j+1];
				data[j+1]=buf;
			}
		}
	}
}

void swap(st_data *d0,st_data *d1){
	st_data *buf;
	buf->jp=d1->jp;
	buf->l=d1->l;
	d1->jp=d0->jp;
	d1->l=d0->l;
	d0->jp=buf->jp;
	d0->l=buf->l;
	return;
}

Measured memory_bytes: 964
#include<iostream>
#include<math.h>
#include<algorithm>
#include<utility>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
#include<functional>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll INF=2e18;
const ll MOD=1e9+7;


ll N;
ll a[100010];
ll dp[100010];
ll minus[100010];
ll plus[100010];

ll extgcd(ll a, ll b, ll& x, ll& y) {
  if (b == 0) {
    x = 1, y = 0; return a;
  }
  ll q = a/b, g = extgcd(b, a - q*b, x, y);
  ll z = x - q * y;
  x = y;
  y = z;
  return g;
}
ll invmod (ll a, ll m) { // a^-1 mod m
  ll x, y;
  extgcd(a, m, x, y);
  x %= m;
  if (x < 0) x += m;
  return x;
}
ll fact[100010],invFact[100010];
void SetFact(ll n,ll mod){
    fact[0]=1;
    invFact[0]=1;
    for(ll i=1;i<=n;i++){
        fact[i]=fact[i-1]*i%mod;
        invFact[i]=invmod(fact[i],mod);
    }
}
ll nCk(ll n, ll r,ll mod){
    if(n<0 || r<0 || r>n)return 0;
    if(r>n/2)r=n-r;
    return fact[n]*invFact[n-r]%mod*invFact[r]%mod;
}

int main(){
    cin>>N;
    SetFact(N+1,MOD);
    map<ll,ll> mp;
    ll first,second=0;
    dp[0]=0;
    for(ll i=0;i<N+1;i++){
        cin>>a[i];
        if(mp.find(a[i])!=mp.end()){
            first=mp[a[i]];
            second=i;
        }
        mp[a[i]]=i;
    }
    ll minus=first+N-second;
    for(ll j=0;j<N+1;j++){
        ll tmp=nCk(N+1,j+1,MOD);
        if(j<=minus){
            tmp-=nCk(minus,j,MOD);
            if(tmp<0)tmp+=MOD;
        }
        cout<<tmp<<endl;
    }
    return 0;
}

Measured memory_bytes: 11648
#include "bits/stdc++.h"
using namespace std;
const int maxn = 1000;
int dp[2][maxn], a[2][maxn];
int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < N; j++) {
            scanf("%d", &a[i][j]);
        }
    }
    memset(dp, 0, sizeof(dp));
    dp[0][0] = a[0][0];
    dp[1][0] = a[0][0] + a[1][0];
    for (int j = 1; j < N; j++) {
        for (int i = 0; i < 2; i++) {
            if (i == 0) dp[i][j] = dp[i][j-1] + a[i][j];
            else dp[i][j] = max(dp[i][j-1], dp[i-1][j])+a[i][j];
        }
    }
    printf("%d\n", dp[1][N-1]);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int DP[12][1030][331];

int search(int n,int limit,int bits,int sum){
  int i,res = 0;
  if(sum < 0 || limit > 10 || sum > 331){return 0;}
  
  if(DP[n][bits][sum] >= 0){
    return DP[n][bits][sum];
  }
  
  if(n == limit){
    if((sum / n) < 10 && (sum%n) == 0 && (bits & (1U << sum/n)) == 0){
      res = 1;
    }
  }else{
    for(i = 0; i < 10; i++){
      if((bits & (1U << i)) == 0){
	res += search(n+1,limit,bits | (1U << i),sum - i*n);
      }
    }
  }
  
  DP[n][bits][sum] = res;
  return res;
}

int main(int argc,char* argv[]){
  int n,s,bn = -1;
  int x,y,z;
  
  while(scanf("%d %d",&n,&s) != EOF){
    if(n != bn){
      for(x=0;x<12;x++){
	for(y=0;y<1030;y++){
	  for(z=0;z<331;z++){
	    DP[x][y][z]=-1;
	  }
	}
      }
    }
    printf("%d\n",search(1,n,0,s));
    bn = n;
  }
  
  return 0;
  
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define REP(i, n) for (ll i = 0; i < (int)(n); i++)
#define RREP(i, n) for (ll i = (int)(n)-1; i > -1 ; i--)
#define IN(T, x) T x;cin >> x;
#define AIN(T, a, n) vector<T> a(n);REP(i, n){cin >> a[i];}
#define A2IN(T1, a, T2, b, n) vector<T1> a(n);vector<T2> b(n);REP(i, n){cin >> a[i] >> b[i];}
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) SORT(a);reverse(ALL(a))
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
#define OUT(x) cout << x << endl
#define BOUT(b) if(b){OUT("Yes");}else{OUT("No");}
const ll INF = 100000007;

int main() {
  IN(ll, N);
  IN(ll, M);
  ll time = M*1900 + (N-M)*100;
  ll P = pow(2, M);
  OUT(P*time);
}





Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n,m;
   cin >> n >> m;
   if(n == 1 and m == 0){
      cout << "0";
      return 0;
   }
   vector<pii> q;
   f(i,0,m){
      int a,b;
      cin >> a >> b;
      a--;
      q.push_back({a,b});
   }
   f(i,0,1000){
      string s = to_string(i);
      if(s.length() == n){
         int c = 1;
         f(i,0,m){
            c = c*(s[q[i].F] == q[i].S+'0');
         }
         if(c){
            cout << s << '\n';
            return 0;
         }
      }
   }
   cout << "-1\n";
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// (setq-default c-basic-offset 2)

struct UnionFind {
  vector<int> p;
  vector<int> s;

  UnionFind(int n) {
    p.resize(n, -1);
    s.resize(n, 1);
  }

  int find(int x) {
    if (p[x] == -1) return x;
    p[x] = find(p[x]);
    return p[x];
  }

  void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (s[x] < s[y]) {
      swap(x, y);
    }
    p[y] = x;
    s[x] += s[y];
  }

  bool same(int x, int y) { return find(x) == find(y); }

  int size(int x) { return s[find(x)]; }
};

int main() {
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  // vector<int> a(m), b(m);
  for (int i = 0; i < m; ++i) {
    // cin >> a[i] >> b[i];
    int ai, bi;
    cin >> ai >> bi;
    --ai;
    --bi;
    uf.unite(ai, bi);
  }
  int ret = 0;
  for (int i = 0; i < n; ++i) {
    ret = max(ret, uf.size(i));
  }
  cout << ret << endl;

  return 0;
}


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

int a, b;
int height[1001];

int main(void){
    
    cin >> a >> b;
    
    height[1] = 1;
    for(int i = 2; i <= 999; ++i) height[i] = height[i - 1] + i;
    
    cout << height[b - a] - b << endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int W = sc.nextInt();
		String[][] campus = new String[H][W];
		for (int i=0;i < H;i++) {
			String input = sc.next();
			for (int j=0;j < W;j++) {
				campus[i][j] = input.substring(j,j+1);
			}
		}
		
		String ans = "Yes";
		outside: for (int i=0;i < H;i++) {
			for (int j=0;j < W;j++) {
				if (campus[i][j].equals("#")) {
					if ((j != 0) && (!campus[i][j-1].equals("#"))) {
						if ((j != W-1) && (!campus[i][j+1].equals("#"))) {
							if ((i != 0) && (!campus[i-1][j].equals("#"))) {
								if ((i != H-1) && (!campus[i+1][j].equals("#"))) {
									ans = "No";
								}
							} 
						}
					}
				}
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
int main(){
  int n;
  cin>>n;
  int h[n],w[n];
  for(int i=0;i<n;i++) cin>>h[i]>>w[i];
  string s[4];
  for(int i=0;i<4;i++) cin>>s[i];
  char c[4]="RGB";
  int dp[1<<16];
  memset(dp,-1,sizeof(dp));
  bool used[1<<16];
  memset(used,0,sizeof(used));
  queue<P> q;
  q.push(P(0,0));
  while(!q.empty()){
    int bit=q.front().first,d=q.front().second;
    q.pop();
    if(~dp[bit]) continue;
    dp[bit]=d;
    for(int i=0;i<n;i++){
      for(int j=-h[i]+1;j<4;j++){
	for(int k=-w[i]+1;k<4;k++){
	  for(int l=0;l<3;l++){
	    int z=bit;
	    for(int a=max(0,-j);a<min(h[i],4-j);a++){
	      for(int b=max(0,-k);b<min(w[i],4-k);b++){
		int y=j+a,x=k+b;
		if(s[y][x]==c[l]) z|=1<<(y*4+x);
		else z&=(1<<16)-(1<<(y*4+x))-1;
	      }
	    }
	    if(dp[z]<0&&!used[z]) q.push(P(z,d+1)),used[z]=1;
	  }
	}
      }
    }
  }
  cout<<dp[(1<<16)-1]<<endl;
  return 0;
}

Measured memory_bytes: 3644
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
	
	int n, m;
	
	while(true){
		cin >> n >> m;
		if(n == 0 && m == 0){
			break;
		}
		if((n * m) % 2 == 0){
			printf("yes\n");
		}else{
			printf("no\n");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1116
/**
 *
 * Contest - Problem X: Nome (link)
 *
 * Abridge version.
 *
 * Solution: text
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define REP(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define REPN(i, N) for (int (i) = 0; (i) < N; (i)++)
#define DEC(i, b, a) for (int (i) = (b); (i) >= (a); (i)--)
#define DECN(i, N) for (int (i) = N - 1; (i) >= 0; (i)--)

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : (vec)) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 510 };

int M[MAX][MAX];
vector<vector<ii>> ps;

void solve()
{
    int inc = 1, x = 1, y = 1, carry = 0;
    vector<ii> path;

    while (M[x][y] != -1)
    {
        auto m = M[x][y];

        if (m % 2)
        {
            if (carry == 0)
            {
                carry = 1;
                path.push_back(ii(x, y));
            } else
            {
                path.push_back(ii(x, y));
                ps.push_back(path);
                path.clear();
                carry = 0;
            }
        } else if (carry)
            path.push_back(ii(x, y));

        if (M[x][y + inc] == -1)
        {
            ++x;
            inc *= -1;
        } else
            y += inc;
    }

    int ans = 0;

    for (const auto& p : ps)
        ans += (p.size() - 1);

    cout << ans << endl;

    for (const auto& p : ps)
        for (size_t i = 1; i < p.size(); ++i)
            cout << p[i - 1].first << " " << p[i - 1].second << " " << p[i].first << " "
                << p[i].second << endl;
}

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

    ll H, W;
    cin >> H >> W;

    memset(M, -1, sizeof(M));

    REP(i, 1, H)
        REP(j, 1, W)
            cin >> M[i][j];

    solve();

    return 0;
}


Measured memory_bytes: 11952
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i];}cout<<endl;
#define pprint(A,m,n) rep(j,0,m){print(A[j],n);}
const long mod=1e9+7;
const int size=1e5;
const long inf=1e9;
int main(){
	int X;cin>>X;
	int a=X/100;
	int b=(X%100+4)/5;
	cout<<(a>=b)<<endl;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc165/tasks/abc165_a 
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define is_in(i, s) (s.find(i) != s.end())
#define all(x) (x).begin(),(x).end()
typedef long long ll;
typedef pair<int,int> P;

#define MAX_N 1000000005


int main() {
	int k,a,b;
	cin >> k >> a >> b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
    return 0;
}



Measured memory_bytes: 3620
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
  class Problem0033
  {
    static void Main()
    {
      var n = int.Parse(Console.ReadLine());
      foreach (var order in Enumerable.Repeat(0, n).Select(s => Console.ReadLine().Split(' ').Select(t => int.Parse(t)).ToArray()))
      {
        var pipeB = 0;
        var pipeC = 0;
        var isSucceeded = true;
        foreach (var x in order)
        {
          if (pipeB < x && pipeC < x)
            if (pipeB > pipeC)
              pipeB = x;
            else
              pipeC = x;
          else if (pipeB < x)
            pipeB = x;
          else if (pipeC < x)
            pipeC = x;
          else
          {
            isSucceeded = false;
            break;
          }
        }
        if (isSucceeded)
          Console.WriteLine("YES");
        else
          Console.WriteLine("NO");
      }
    }
  }
}

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

int i,j,k,l;
int x,y;
int a,b;
int N;

long long fiv(long long n)
{
	
	return n*n*n*n*n;
}

int main()
{
    //#ifndef ONLINE_JUDGE
    //  freopen("input.txt","r",stdin);
    //  freopen("output.txt","w",stdout);
    //#endif
	
	cin >> x;
	for (long long i = -200; i <= 200; i++)
	{
		for (long long j = -200; j <= 200; j++) 
		{
			if (fiv(i)-fiv(j)== x) 
			{
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	

}










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

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main(){
	int N, M;
	cin >> N >> M;
	vector<vector<int>> G(N);
	rep(i,M){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].emplace_back(b);
		G[b].emplace_back(a);
	}
	rep(i,G[0].size()){
		int next=G[0][i];
		rep(j,G[next].size()){
			if(G[next][j]==N-1){
				cout << "POSSIBLE" << endl;
				return 0;
			}
		}
	}
	cout << "IMPOSSIBLE" <<  endl;

	return 0;
}

Measured memory_bytes: 12016
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
typedef long long LL;

int main() {
	int ans = 0;
	int k, p;
	cin >> k >> p;
	int a;
	for (int i = 0; i < p; i++) {
		cin >> a;
		ans = max( ans,a - 1 - (k - a));
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
from sys import stdin

H, W = [int(i) for i in stdin.readline().rstrip().split()]
a = [[int(i) for i in stdin.readline().rstrip().split()] for _ in range(H)]

ans = []
for row in range(H):
    for col in range(W):
        if row == H - 1 and col == W - 1:
            break

        if a[row][col] % 2 == 1 and col < W - 1:
            ans.append([row + 1, col + 1, row + 1, col + 1 + 1])
            a[row][col] -= 1
            a[row][col + 1] += 1
        elif a[row][col] % 2 == 1 and col == W - 1:
            ans.append([row + 1, col + 1, row + 1 + 1, col + 1])
            a[row][col] -= 1
            a[row + 1][col] += 1

print(len(ans))
for t, u, s, v in ans:
    print(t, u, s, v)


Measured memory_bytes: 30268
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    if A <= K:
        ans += A
        K -= A
        if K > 0:
            if B <= K:
                K -= B
                if K > 0:
                    if C <= K:
                        ans -= C
                        K -= C
                    else:
                        ans -= K

    else:
        ans += K
    print(ans)

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(A, B, C, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9224
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

const int N=1e5+1;

int p[11][11];

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,d,x; cin >> n >> d >> x;
    vector<int> dp(N,0);
    for(int i=0;i<=x;i++){
        dp[i]=1;
    }
    for(int i=0;i<d;i++){
        for(int j=0;j<n;j++){
            cin >> p[i][j];
        }
    }
    for(int i=0;i+1<d;i++){
        for(int j=0;j<N;j++){
            if(j<=x)dp[j]=x;
            else dp[j]=0;
        }
        for(int j=0;j<n;j++){
            for(int k=p[i][j];k<=x;k++){
                dp[k]=max(dp[k],dp[k-p[i][j]]+p[i+1][j]-p[i][j]);
            }
        }
        x=dp[x];
    }
    printf("%d\n",x);
}


Measured memory_bytes: 3376
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    A=int(input())
    B=int(input())
    C=int(input())
    X=int(input())
    ans=0
    for i in range(A+1):
        for j in range(B+1):
            for k in range(C+1):
                if i*500+j*100+k*50==X:
                    ans+=1
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38896
import collections

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    cnt = collections.defaultdict(int)
    for var in a:
        cnt[var] += 1
    
    sum_a = sum(a)
    
    q = int(input())
    for _ in range(q):
        b, c = list(map(int, input().split()))
        diff = (c-b) * cnt[b]
        sum_a += diff
        print(sum_a)
        cnt[c] += cnt[b]
        cnt[b] = 0
        
if __name__ == '__main__':
    main()

Measured memory_bytes: 24132
def inpl(): return list(map(int, input().split()))
N, K = inpl()
X = [0] + [1/N if i <= N else 0 for i in range(1, K)]
w = max(0, N-K+1)/N

for i in range(K):
    if (i*2 >= K):
        w += X[i]/2
    else:
        X[i*2] += X[i]/2
print(w)

Measured memory_bytes: 5128
S = input()
le = int(S[0:2])
ri = int(S[2:4])
if (le == 0 and ri == 0) or (le == 0 and ri > 12) or (le > 12 and ri == 0) or (le>12 and ri>12):
  print("NA")
elif 0 < le <= 12 and 0 < ri <= 12:
  print("AMBIGUOUS")
elif 0 < le <= 12 and ( ri == 0 or ri >12 ):
  print("MMYY")
elif 0 < ri <= 12 and ( le == 0 or le >12 ):
  print("YYMM")



Measured memory_bytes: 3064
function Main(input) {
    // 1行目がinput[0], 2行目がinput[1], …に入る
    input = input.split("\n");
    chars = input[0].split("");
		var hash = {}
		for(var i=0;i < chars.length; i++){
			if(hash[chars[i]]){
				console.log("no");
				return;
			}else{
				hash[chars[i]] = 1;
			}
		}
		console.log("yes");
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int count = 0;
    int answer = 0;
    for(int i = 0; i < n; i++){
        if(s.at(i) == 'I'){
            count = count + 1;
        } else {
            count = count - 1;
        }
        answer = max(answer, count);
    }
    cout << answer << endl;
}

Measured memory_bytes: 256
import Control.Applicative
import Control.Monad

main = do
    n <- readLn
    ss <- replicateM n ( map read.words <$> getLine ) ::IO [[Int]]
    let resid = concat[concat[" "++unwords[ show(sum [ v| (b:f:r:v:_) <- ss, (b,f,r) == (x,y,z)]) | z <- [1..10]] ++ "\n"| y <- [1..3]]++"####################\n"| x <- [1..4]]
    putStr $ take (length resid - 21) resid

Measured memory_bytes: 4136
#include<bits/stdc++.h>
 
using namespace std;
 
typedef complex<double> P;
 
int n,m;
double p[50];
 
double cal(int a,int b,int c){
 
  double res;
 
  P s=P(cos(p[a]),sin(p[a])),t=P(cos(p[b]),sin(p[b])),u=P(cos(p[c]),sin(p[c]));
 
  double aa=abs(s-t),bb=abs(t-u),cc=abs(u-s);
  double ss=(aa+bb+cc)/2;
 
  res=sqrt(ss*(ss-aa)*(ss-bb)*(ss-cc));
 
  return res;
}
 
int main(){
 
 
  while(cin>>n>>m,n){
 
    for(int i=0;i<n;i++){
      cin>>p[i];
      p[i]*=2*M_PI;
    }
 
  double dp[50][50][50]={};
   
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      for(int k=2;k<m;k++)
    for(int l=j+1;l<n;l++){
      dp[i][l][k+1]=max(dp[i][l][k+1],dp[i][j][k]+cal(i,j,l));
    }
 
  double ans=0;
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)ans=max(ans,dp[i][j][m]);
   
  printf("%.6f\n",ans);
   
  }
 
 
   
  return 0;
}

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

int main() {
	string order, s;
	int n;
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> order;
		cin >> s;
		for(int j = order.size() - 1; j >= 0; --j){
			if(order[j] == 'J'){
				s = s[s.size() - 1] + s.substr(0, s.size() - 1);
			}
			if(order[j] == 'C'){
				s = s.substr(1, s.size() - 1) + s[0];
			}
			if(order[j] == 'E'){
				for(int k = 0; k < s.size() / 2; ++k)
					swap(s[k], s[k + s.size() / 2 + s.size() % 2]);
			}
			if(order[j] == 'A'){
				reverse(s.begin(), s.end());
			}
			if(order[j] == 'P'){
				for(int k = 0; k < s.size(); ++k){
					if('0' <= s[k] && s[k] <= '9'){
						if(s[k] == '0')
							s[k] = '9';
						else
							s[k] -= 1;
					}
				}
			}
			if(order[j] == 'M'){
				for(int k = 0; k < s.size(); ++k){
					if('0' <= s[k] && s[k] <= '9'){
						if(s[k] == '9')
							s[k] = '0';
						else
							s[k] += 1;
					}
				}
			}
		}
		cout << s << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
	ll n,k;cin>>n>>k;
	vector<int> a(n);
	for(int i=0;i<n;i++)cin>>a[i];
	ll tina=0;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			if(a[i]>a[j])tina++;
		}
	}
	ll ans=tina*k;
	tina=0;
	for(int i=0;i<n;++i)
	{
		for(int j=0;j<n;j++)
		{
			if(a[i]>a[j])tina++;
		}
	}
	 k=(k-1)*k/2%1000000007;
	ans+=k*tina;
	cout<<ans%1000000007<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define LLMAX (1ll << 60) - 1
#define INTMAX (1 << 30) - 1
#define MOD 1000000007 
#define NMAX 1000*100+1

#define numberOfSetBits(S) __builtin_popcount(S) // __builtin_popcountl(S) __builtin_popcountll(S)
#define MSET(x,y) memset(x,y,sizeof(x))
#define gcd(a,b) __gcd(a,b)
#define all(x)  x.begin(),x.end()
#define isOn(S, j) (S & (1 << j))
#define endl '\n'
#define setBit(S, j) (S |= (1 << j))
#define clearBit(S, j) (S &= ~(1 << j))
#define toggleBit(S, j) (S ^= (1 << j))
#define print(x)    for(auto it:x) cout<<it<<' '; cout<<endl;
#define printii(x)  for(auto it:x) cout<<it.F<<' '<<it.S<<'\t';  cout<<endl;
#define in(x,n)   for(int e=0;e<n;e++){ll y;cin>>y;x.pb(y);}

#define vi vector<ll>
#define vvi vector<vi>
#define ii pair<ll,ll>
#define pll pair<ll,ll>
#define vii vector<ii>
#define vvii vector<vii>
#define viii vector<pair<ii,ll>>
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define mc(a,b,c) mp(mp(a,b),c)
vi a;
ll get(ll x){
    ll y = 0;
    for(int i=0;i<a.size();i++){
        y+=(a[i]-x)*(a[i]-x);
    }
    return y;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x,t,m,y,z;
    z= 0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x;
        a.pb(x);
        z+=x;
    }
    z/=n;
    cout<<min(get(z),min(get(z+1),get(z-1)));



    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            int[] A = new int[n];

            for (int i = 0; i < n; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine(GetLIS(A));
        }

        static int GetLIS(int[] A)
        {
            const int INFTY = int.MaxValue;
            int n = A.Length;

            int[] L = Enumerable.Repeat(INFTY, n).ToArray();
            int[] id = new int[n];
            int ret = 0;

            for (int i = 0; i < n; i++)
            {
                id[i] = LowerBound(L, A[i]);
                L[id[i]] = A[i];

                ret = Math.Max(ret, id[i] + 1);
            }

            return ret;
        }

        static int LowerBound(int[] arr, int value)
        {
            int low = 0;
            int high = arr.Length;
            int mid;

            while (low < high)
            {
                mid = ((high - low) >> 1) + low;        // (low + high) / 2
                if (arr[mid] == value) return mid;
                if (arr[mid] < value) low = mid + 1;
                else high = mid;
            }
            return low;
        }
    }
}

Measured memory_bytes: 11624
#include<iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
using namespace std;
#define rep(i,ra,re) for((i)=ra;(i)<(re);(i)++)
#define _rep(i,ra,re) for((i)=ra;(i)>(re);(i)--)
#define rep_(i,ra,re) for((i)=ra;(i)<=(re);(i)++)
#define _rep_(i,ra,re) for((i)=ra;(i)>=(re);(i)--)
#define put(n) cout << n << " "; 
#define puts(n) cout << n << endl;
#define pu(n) cout << n;
#define mod 1000000007
int i,j,k,l;
static const int MAX_N=10e5;
long A[MAX_N],B[MAX_N-1],ANS[MAX_N+1];
long sum;
int main(void){
	int N;
		cin >> N;
	rep(i,0,N){
		cin >> A[i];
		sum+=A[i];
		A[i]*=2;
	}
	rep(i,0,N-1){
		B[i]=A[i+1]-A[i];
	}
	long fa=0,fb=0;
	long cur=0;
	rep(i,0,N-1){
		if(i%2==0){
			cur+=fa+B[i];
			fa+=B[i];
		}else{
			cur+=fb-B[N-i-1];
			fb-=B[N-i-1];
		}
	}
	
	ANS[0]=ANS[N]=(sum-cur)/N;
	rep(i,1,N){
		if(i%2==0){
			ANS[i]=ANS[i-2]+B[i-2];
		}else{//N-i-1
			ANS[N-i-1]=ANS[N-i+1]-B[N-i-1];
		}
	}
	rep(i,0,N){
		put(ANS[i]);
	}puts("");
	return 0;
}


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

int main() {
	long long n,ww;
	cin>>n>>ww;
	long long v[n+1],w[n+1];
	long long dp[n+1][n*1000+1];
	for(long long i=1;i<=n;i++){
	        cin>>w[i]>>v[i];
	
	}for(long long i=0;i<=n*1000;i++){
	       dp[0][i]=-1;
	}for(long long j=0;j<=n;j++){
	    dp[j][0]=0;
	}long long ans=0;
	for(long long i=1;i<=n;i++){
	    for(long long j=1;j<=n*1000;j++){
	        dp[i][j]=-1;
	        if((j-v[i])>-1&&dp[i-1][j-v[i]]!=-1&&dp[i-1][j-v[i]]+w[i]<=ww){
	            dp[i][j]=dp[i-1][j-v[i]]+w[i];
	        }if(dp[i-1][j]!=-1){
	            if(dp[i][j]!=-1){
	                dp[i][j]=min(dp[i][j],dp[i-1][j]);
	            }else{
	                dp[i][j]=dp[i-1][j];
	            }
	        }
	        if(dp[i][j]!=-1){
	            ans=max(ans,j);
	        }
	    }
	}cout<<ans;
	
}


Measured memory_bytes: 79104
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
int main() {
    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vl p(a), q(b), r(c);
    rep(i, a) cin >> p[i];
    rep(i, b) cin >> q[i];
    rep(i, c) cin >> r[i];
    sort(all(p));
    sort(all(q));
    rep(i, x) r.push_back(p[a - i - 1]);
    rep(i, y) r.push_back(q[b - i - 1]);
    sort(all(r), greater<ll>());
    ll ans = 0;
    rep(i, x + y) ans += r[i];
    cout << ans << endl;
}

Measured memory_bytes: 6128
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
typedef long long ll;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N, A, B;
    cin >> N >> A >> B;
    int C = B - A - 1;
    if (C % 2 == 0) {
        cout << "Borys" << endl;
    } else {
        cout << "Alice" << endl;
    }
}


Measured memory_bytes: 3632
import Control.Applicative
import Control.Monad
import Data.List
import Data.Array
import Data.Char

main = do
  [x1, y1, x2, y2] <- map (read::String -> Int) . words <$> getLine
  let (x3, y3) = (x2 - y2 + y1, y2 + x2 - x1)
      (x4, y4) = (x1 - y2 + y1, y1 + x2 - x1)
  putStrLn $ show x3 ++ " " ++ show y3 ++ " " ++ show x4 ++ " " ++ show y4

Measured memory_bytes: 508
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

type Problem struct {
	Num   int
	Bonus int
	Base  int
}

var MinProblem = 100*10 + 1

func main() {
	s := IOInitialize()
	D := Int(s)
	G := Int(s)
	problems := scanNums(s, D)
	solveNums := []int{}
	calc(problems, G, &solveNums, 0, 0)
	fmt.Println(minSlice(solveNums))
}

func calc(problems []Problem, G int, solveNums *[]int, sum int, problemNum int) {
	if len(problems) == 0 {
		panic("unreachable")
	}
	for i := 0; i < len(problems); i++ {
		score := problems[i].Num*problems[i].Base + problems[i].Bonus
		if sum+score >= G {
			target := G - sum
			n := target / problems[i].Base
			if target%problems[i].Base != 0 {
				n++
			}
			*solveNums = append(*solveNums, problemNum+min(problems[i].Num, n))
		} else {
			_sum := sum + score
			num := problems[i].Num
			_problems := remove(problems, i)
			calc(_problems, G, solveNums, _sum, problemNum+num)
		}
	}
}

func remove(slice []Problem, index int) []Problem {
	_slice := []Problem{}
	for i, v := range slice {
		if i != index {
			_slice = append(_slice, v)
		}
	}
	return _slice
}

func min(nums ...int) int {
	res := nums[0]
	for _, num := range nums {
		if res > num {
			res = num
		}
	}
	return res
}

func minSlice(nums []int) int {
	res := nums[0]
	for _, num := range nums {
		if res > num {
			res = num
		}
	}
	return res
}

func IOInitialize() *bufio.Scanner {
	s := bufio.NewScanner(os.Stdin)
	s.Split(bufio.ScanWords)
	return s
}

func Int(s *bufio.Scanner) int {
	if !s.Scan() {
		panic("scan error")
	}

	value, err := strconv.Atoi(s.Text())
	if err != nil {
		panic("text to int error")
	}
	return value
}

func scanNums(s *bufio.Scanner, len int) (nums []Problem) {
	for i := 0; i < len; i++ {
		num := Int(s)
		bonus := Int(s)
		nums = append(nums, Problem{Num: num, Bonus: bonus, Base: (i + 1) * 100})
	}
	return
}


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


void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    input();
  	
  	ll n;
  	cin>>n; 	
  	cout<<1000*(ceil(n*1.0/1000))-n;
  	
}




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

int main(){
    int a,b,k;
    cin >> a >> b >> k;
    int c = min(a,b);
    int count = 0;
    for (int i = c; i > 0; i--){
        if (a % i == 0 && b % i == 0){
            count++;
            if (count == k){
                cout << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())

i = 2
if N==1:
    ans=1
else:
    while not i>N:
        ans = i
        i = i*2

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 2940
n=int(input())
alp=["z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y"]
ans=""
while n>0:
    ans=alp[n%26]+ans
    n=(n-1)//26

print(ans)


Measured memory_bytes: 9092
n = int(input())
s = [0 for s in range(13)]
h = [0 for s in range(13)]
c = [0 for s in range(13)]
d = [0 for s in range(13)]
for i in range(n):
    design, N = input().split()
    N = int(N)
    if design == "S":
        s[N-1] = 1
    elif design == "H":
        h[N-1] = 1
    elif design == "C":
        c[N-1] = 1
    else:
        d[N-1] = 1

for i in range(13):
    if s[i] == 0:
        print("S {0}".format(i + 1))

for i in range(13):
    if h[i] == 0:
        print("H {0}".format(i + 1))

for i in range(13):
    if c[i] == 0:
        print("C {0}".format(i + 1))

for i in range(13):
    if d[i] == 0:
        print("D {0}".format(i + 1))
        

Measured memory_bytes: 7756
#include <bits/stdc++.h>
using namespace std;
const int M=110;
char s[M];
int dp[M][5][3];
int main(int argc, char const *argv[])
{
	scanf("%s",s+1);
	int k;cin>>k;
	int len=strlen(s+1);
	dp[1][0][0]=1;
	dp[0][0][0]=1;
	for(int i=1;i<=len;i++){
		for(int j=0;j<=3;j++){//j个非零数字
			for(int p=0;p<2;p++){//p=0表示一定小于
				int num=s[i]-'0';
				for(int d=0;d<=9;d++){
					int ni=i+1,nj=j,np=p;
					if(d!=0)nj++;
					if(nj>k)continue;
					if(np==0){
						if(d>num)continue;
						if(d<num)np=1;
					}
					dp[ni][nj][np]+=dp[i][j][p];
				}
			}
		}
	}
	cout<<dp[len+1][k][0]+dp[len+1][k][1]<<endl;
	return 0;
}

Measured memory_bytes: 256
H, W, K = [int(v) for v in input().strip().split(" ")]
C = []
for i in range(H):
    row = [v for v in input().strip()]
    C.append(row)

def calc(C):
    num = 0
    for i in range(H):
        c = C[i]
        for j in range(W):
            if C[i][j] == "#":
                num += 1
    return num

def maskC(C, rowcol):
    masked_C = []
    for i in range(H):
        row = []
        for j in range(W):
            row.append(C[i][j])
        masked_C.append(row)

    rows, cols = [], []
    for index in rowcol:
        if index < H:
            rows.append(index)
        else:
            cols.append(index - H)

    for row in rows:
        masked_C[row] = ["!"] * W
    for col in cols:
        for i in range(H):
            masked_C[i][col] = "!"
    return masked_C


def search(C, From=0, rowcol=[], result=0):
    # print(rowcol)
    masked_C = maskC(C, rowcol)
    num = calc(masked_C)
    # if rowcol == [0, 2]:
    #     print(masked_C)
    # print(num)
    if num == K:
        result += 1
    for i in range(From, H + W):
        result = search(C, i+1, rowcol + [i], result)
    return result

print(search(C))

Measured memory_bytes: 9164
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const int MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
}
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(a%b,b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

ll N,M;

bool isOK(vector<ll>X,ll mid){
	//mid分以内に行けるかどうか
	ll right=0;
	for(int i=0;i<M;i++){
		if(right+mid>=X[i]){
			right=max(X[i],max(X[i]+mid-((X[i]-right)*2),X[i]+(mid-(X[i]-right))/2));
		}
	}
	return (right>=N-1);
}


int main(){
    init();
	string s;
	cin>>s;
	string t=s;
	reverse(t.begin(),t.end());
	ll ans=0;
	for(int i=0;i<t.size();i++){
		if(t[i]!=s[i])ans++;
	}
	cout<<(ans+1)/2<<endl;
}

Measured memory_bytes: 256
import copy
h,w,k= map(int, input().split())
gr = [list(input()) for i in range(h)]
ans = 0
for i in range(1<<h):
    for j in range(1<<w):
        grnow = copy.deepcopy(gr)
        for i2 in range(h):
            if(1<<i2) & i:
                grnow[i2]=['*']*w
        for j2 in range(w):
            if(1<<j2) & j:
                for k2 in range(h):
                    grnow[k2][j2]='*'
        cnt = 0
        for i2 in range(h):
            for j2 in range(w):
                if grnow[i2][j2]=='#':
                    cnt += 1

        if cnt == k:
            ans += 1

print(ans)




Measured memory_bytes: 72036
def main():
    n = str(input())
    
    if n == 'SUN':
        print(7)
    elif n=='SAT':
        print(1)
    elif n=='FRI':
        print(2)
    elif n=='THU':
        print(3)
    elif n=='WED':
        print(4)
    elif n=='TUE':
        print(5)
    elif n=='MON':
        print(6)

if __name__ == '__main__':
    main()



Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1e5)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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; }
typedef pair <ll,ll> P;

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

int main()
{
    ll M, D;
    cin >> M >> D;
    if (D < 22) print(0);
    else {
        ll cnt = 0;
        for(ll i = 22; i <= D; i++) {
            if (i / 10 < 2 || i%10 < 2) continue;
            ll tmp = (i/10) * (i%10);
            if (tmp <= M) cnt++;
            
        }
        print(cnt);
    }
    return 0;
}

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

int a[3];

int main()
{
	for(int i = 0; i < 3; i ++)
		cin >> a[i];
	sort(a, a + 3);
	if(a[0] == 5 && a[1] == 5 && a[2] == 7)	cout << "YES" << endl;
	else	cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
   int n,m,sum=0,temp;
   scanf("%d",&n);
   temp=n;
   while(temp>0)
   {
       m=temp%10;
       sum=sum+m;
       temp=temp/10;
   }
    if(n%sum==0)
    {
        printf("Yes\n");
    }
    else{printf("No\n");}
    return 0;
}


Measured memory_bytes: 128
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int n,m; cin>>n>>m;
    vector<vector<int>> path(n);
    vector<int> visited(n,0);
    vector<pp> data(0);
    set<pp> edges;
    rep(i,m){
        int a,b; cin>>a>>b;
        a--; b--;
        edges.insert(mk(a,b));
        edges.insert(mk(b,a));
    }
    rep(i,n)rep(j,n){
        if(i==j) continue;
        if(!(edges.count(mk(i,j))))
        path[i].push_back(j);
    }
    rep(i,n){
        if(visited[i]!=0) continue;
        visited[i]=1;
        int lcnt=1,rcnt=0,s,from;
        queue<pp> que;
        que.push(mk(i,-1));
        while(!(que.empty())){
            tie(s,from)=que.front();
            que.pop();
            if(from!=-1 && visited[s]!=0) continue;
            if(from!=-1){
                if(visited[from]==1){
                    visited[s]=-1;
                    rcnt++;
                }
                else{
                    visited[s]=1;
                    lcnt++;
                }
            }
            for(auto to:path[s]){
                if(visited[to]!=0) continue;
                que.push(mk(to,s));
            }
        }
        data.push_back(mk(lcnt,rcnt));
    }
    rep(i,n)for(auto to:path[i]){
        if(visited[i]==visited[to]){
            cout<<-1<<endl;
            return 0;
        }
    }
    vector<vector<int>> dp(data.size()+1,vector<int>(n+1,0));
    dp[0][0]=1;
     rep(i,data.size())rep(j,n+1){
         if(dp[i][j]){
             dp[i+1][j+data[i].first]=1;
             dp[i+1][j+data[i].second]=1;
         }
     }
    int k=n*(n-1)/2,ans=inf;
    rep(i,n+1){
        if(dp[data.size()][i]){
            int cnt=k-i*(n-i);
            ans=min(ans,cnt);
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 25088
#include<iostream>
#include<climits>
#include<math.h>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include <string>
#include <complex>
#include <functional>
using namespace std;
typedef pair<int,int> P;
double dat[100][100];
int dp[6][1010];//動的計画法
int prime[10000001];
char str[1010][1010];
vector<pair<int,int> > pc[100001];
int ABS(int a){return max(a,-a);}
int main(){
	int a,b;
	char op;
	cin>>a;cin>>op;cin>>b;
	if(op=='+') cout<<a+b<<endl;
	else cout<<a-b<<endl;
	return 0;
}

Measured memory_bytes: 4352
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ALDS1_7_A {
    class Node {
        public int Parent { get; set; }
        public int Depth { get; set; }
        public List<int> Children { get; set; }

        public Node() {
            Parent = -1;
            Children = new List<int>();
        }
    }

    class Program {
        static void Main(string[] args) {
            int n = int.Parse(Console.ReadLine());
            Dictionary<int, Node> nodes = Enumerable.Range(0, n)
                .ToDictionary(i => i, i => new Node());

            for(int i = 0; i < n; i++) {
                string[] input = Console.ReadLine().Split(' ');
                int nodeId = int.Parse(input[0]);
                int childrenVolume = int.Parse(input[1]);
                for (int j = 0; j < childrenVolume; j++) {
                    int childId = int.Parse(input[j + 2]);
                    nodes[nodeId].Children.Add(childId);
                    nodes[childId].Parent = nodeId;
                }
            }

            int root = GetParent(nodes);
            CheckDepth(nodes, root);
            Print(nodes);
        }

        static int GetParent(Dictionary<int,Node> nodes) {
            for (int i = 0; i < nodes.Count; i++)
                if (nodes[i].Parent == -1)
                    return i;
            return -1;
        }

        static void CheckDepth(Dictionary<int, Node> nodes,int root) {
            Stack<int> stk = new Stack<int>(nodes[root].Children);
            while (stk.Count > 0) {
                int cur = stk.Pop();
                nodes[cur].Depth = nodes[nodes[cur].Parent].Depth + 1;
                if (nodes[cur].Children.Count != 0) {
                    foreach (var child in nodes[cur].Children) {
                        stk.Push(child);
                    }
                }
            }
        }

        static void Print(Dictionary<int, Node> nodes) {
            StringBuilder sb = new StringBuilder();
            for(int i = 0; i < nodes.Count; i++) {
                sb.Append("node " + i);
                sb.Append(": parent = " + nodes[i].Parent);
                sb.Append(", depth = " + nodes[i].Depth);
                sb.Append(", " + GetType(nodes, i));
                sb.Append(", [");
                for(int j = 0; j < nodes[i].Children.Count; j++) {
                    if (j > 0)
                        sb.Append(", ");
                    sb.Append(nodes[i].Children[j]);
                }
                sb.AppendLine("]");
            }
            Console.Write(sb);
        }

        static string GetType(Dictionary<int,Node>nodes,int index) {
            if (nodes[index].Parent == -1)
                return "root";
            if (nodes[index].Children.Count == 0)
                return "leaf";
            return "internal node";
        }
    }
}

Measured memory_bytes: 62116
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(int)(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;
const ll mod = 1000000007;

int main()
{
  ll n; cin >> n;
  vector<ll> d(n);
  rep(i, n) cin >> d[i];
  ll m; cin >> m;
  vector<ll> t(m);
  rep(i, m) cin >> t[i];

  map<ll, ll> mpd;
  rep(i, n) mpd[d[i]]++;
  map<ll, ll> mpt;
  rep(i, m) mpt[t[i]]++;

  for (auto v:mpt) {
    if (mpd[v.first] < v.second) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

  return 0;
}


Measured memory_bytes: 28416