akhauriyash/Code-Regression huggingface dataset:
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <cstdio>
#include <string>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>

#define isNum(a) (a >= '0' && a <= '9')
#define SP putchar(' ')
#define EL putchar('\n')
#define File(a) freopen(a ".in", "r", stdin), freopen(a ".out", "w", stdout)

template<class T>
void read(T&);
template<class T>
void write(const T&);

typedef long long ll;
typedef const long long & cll;
typedef const int & ci;
typedef std::pair<int, int> pii;
const int iinf = 2147483647;
const ll llinf = 9223372036854775807ll;
using std::min;
using std::max;
using std::abs;
using std::sort;
const int N = 205;
const long double PI = acos(-1);

class Vector {
public:
  long double x, y;
  Vector(long double x = 0, long double y = 0) : x(x), y(y) {}
  Vector operator + (const Vector i) {
    return Vector(x + i.x, y + i.y);
  }
  double Rad() const {
    if (x < 0) {
      return Vector(-x, -y).Rad() + PI;
    } else {
      if (y < 0) {
        return PI - Vector(x, -y).Rad();
      } else {
        if (x == 0) {
          return 0;
        } else {
          return PI / 2 - atan(y / x);
        }
      }
    }
  }
  bool operator < (const Vector i) const {
    return this->Rad() < i.Rad();
  }
}v[N];

int main () {
  int n;
  read(n);
  for (int i = 1; i <= n; ++i) {
    std::cin >> v[i].x >> v[i].y;
  }
  sort(v + 1, v + n + 1);
  for (int i = 1; i <= n; ++i) {
    v[i + n] = v[i];
  }
  long double ans = 0;
  for (int i = 1; i <= n; ++i) {
    Vector now;
    for (int j = i; j <= (n << 1); ++j) {
      if (j - i >= n) {
        break;
      }
      now = now + v[j];
      ans = max(ans, now.x * now.x + now.y * now.y);
    }
  }
  std::cout.precision(20);
  std::cout << std::fixed << sqrt(ans) << std::endl;
  return 0;
}

template<class T>
inline void read(T &Re) {
  T k = 0;
  char ch = getchar();
  int flag = 1;
  while (!isNum(ch)) {
    if (ch == '-') {
      flag = -1;
    }
    ch = getchar();
  }
  while (isNum(ch)) {
    k = (k << 1) + (k << 3) + ch - '0';
    ch = getchar();
  }
  Re = flag * k;
}
template<class T>
inline void write(const T &Wr) {
  if (Wr < 0) {
    putchar('-');
    write(-Wr);
  } else {
    if (Wr < 10) {
      putchar(Wr + '0');
    } else {
      write(Wr / 10);
      putchar((Wr % 10) + '0');
    }
  }
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
# define ll  long long int
# define ld  long double
# define pb push_back
# define pp pop_back
# define ff first
# define ss second
# define mp make_pair
# define ac accumulate
# define mod 1000000007
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int mxN=5e5, M=1e9+7;
int n, m;
ll iv[mxN+1], f1[mxN+1], f2[mxN+1];
 
ll nck(int n, int k) {
	return f1[n]*f2[k]%M*f2[n-k]%M;
}

int  main()
{
    #ifndef ONLINE_JUDGE
       freopen("input.txt", "r", stdin);
       freopen("output.txt", "w", stdout);
    #endif
     IOS
    iv[1]=1;
	for(int i=2; i<=mxN; ++i)
		iv[i]=M-M/i*iv[M%i]%M;
	f1[0]=f2[0]=1;
	for(int i=1; i<=mxN; ++i) {
		f1[i]=f1[i-1]*i%M;
		f2[i]=f2[i-1]*iv[i]%M;
	}
 
	cin >> n >> m;
	ll ans=nck(m,n)%M*f1[n]%M;
	ll temp = 0;
	for(int i = 1; i <= n; i++){
		ll c = i&1? 1 : -1;
		temp = (temp%M + (c*nck(n,i)%M*nck(m-i,n-i)%M*f1[n-i]%M)%M)%M;
	}
	cout << (ans%M - temp%M + M)*ans%M;
	return 0;
}

Measured memory_bytes: 15336
#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
const int N=1e5+5;
const double eps=1e-4;
typedef long long ll;
typedef pair<int,int> pii;
int a[N];
int main()
{
    int n,m,c;
    scanf("%d%d%d",&n,&m,&c);
    for(int i=0;i<m;i++)
    {
        scanf("%d",&a[i]);
    }
    int ans=0;
    for(int i=0;i<n;i++)
    {
        ll temp=0;
        for(int j=0;j<m;j++)
        {
            int b;
            scanf("%d",&b);
            temp+=b*1ll*a[j];
        }
        temp+=c;
        if(temp>0)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
	ll tot, n; cin>>tot>>n;
	for(int i = 0; i < n ;i++)
	{
		ll k; cin>>k;
		tot-=k;
		if(tot<=0)
		{
			cout<<"Yes\n";
			return 0;
		}
	}
	cout<<"No\n";
	return 0;
}

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

void Print1(int t[], int n)
{
	int i;
	for(i=0;i<n;i++)
	{
		if(i)
			printf(" ");
		printf("%d", t[i]);
	}
	printf("\n");
}

void Print2(int t[], int n)
{
	int i;
	for(i=n-1;i>=0;i--)
	{
		if(i!=n-1)
			printf(" ");
		printf("%d", t[i]);
	}
	printf("\n");
}

int main()
{
	int h, w, n, i,j=0, m, res[100][100], num=1, tmp[100], flag=0;
	scanf("%d%d", &h, &w);
	scanf("%d", &n);
	for(i=0;i<n;i++)
	{
		scanf("%d", &m);
		while(m--)
		{
			tmp[j++] = num;
			if(j==w)
			{
				if(flag==0)
					Print1(tmp, w);
				else
					Print2(tmp, w); 
				flag = 1 - flag;
				j = 0;
			}
		}
		num++;
	}
	return 0;	
} 

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

int main() {
    int n; cin >> n;
    vector<int> a(n),num(100002,0);
    ll ans=0;
    rep(i,n){
        cin>>a[i];
        num[a[i]]++;
        ans+=a[i];
    }
    int q;
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        ans+=num[b]*(c-b);
        num[c]+=num[b];
        num[b]=0;
        cout << ans << endl;
    }
}

Measured memory_bytes: 4004
#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for(int i = 0; i < N; i++) cin >> a[i];
    int max_a = *max_element(a.begin(), a.end());
    int min_a = *min_element(a.begin(), a.end());
    cout<< max_a - min_a <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif // LOCAL
using ll = long long ;
ll a, b;

int main(){
    cin >> a >> b;
    cout << a * b / __gcd(a, b) << endl;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int parent[MAX],tot[MAX];
ll ans[MAX];
int root(int child)
{
    while(parent[child]!=child)
    {
        parent[child]=parent[parent[child]];
        child=parent[child];
    }
    return child;
}
void node_union(int x,int y)
{
    int a=root(x);
    int b=root(y);
    parent[min(a,b)]=parent[max(a,b)];
    tot[max(a,b)]=tot[a]+tot[b];
   // cout<<a<<" "<<b<<" "<<tot[max(a,b)]<<" "<<tot[a]<<" "<<tot[b]<<endl;
}
ll sum(ll x)
{
    return (x*(x+1))/2;
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    for(int i=0; i<=MAX-5; i++)
        parent[i]=i,tot[i]=1;
    vector<pair<int,int> >v;
    int n,m;
    cin>>n>>m;
    ll cur=0;
    for(int i=0; i<m; i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    cur=sum(n-1);
    ans[m-1]=cur;
    ll rem=0;
    for(int i=m-1; i>0; i--)
    {
        int x=v[i].first;
        int y=v[i].second;
        int a=root(x);
        int b=root(y);
        if(a!=b)
        {
            cur+=sum(tot[a]-1);
            cur+=sum(tot[b]-1);
            node_union(x,y);
            ll temp=tot[root(x)];
            cur-=sum(temp-1);
        }
        ans[i-1]=cur;
    }
    for(int i=0; i<m; i++)
        cout<<ans[i]<<endl;


    return 0;
}


Measured memory_bytes: 12600
#!/usr/bin/env python3
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
MAX = 10**18
if A[0] == 0:
    print(0)
    exit()
ans = 1
for i in reversed(range(N)):
    ans *= A[i]
    if ans > MAX:
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21712
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007

int main()
{  
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll n;
    cin>>n;
    ll a[n],dp[n][n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=n-1;i>=0;i--)
    {
        for(int j=i;j<n;j++)
        {
            if(i == j)dp[i][j]=a[i];
            else if(i+1 == j)dp[i][j]=abs(a[i]-a[i+1]);
           // else dp[i][j]=max(a[i]+min(dp[i+2][j]-a[i+1],dp[i+1][j-1]-a[j]),a[j]+min(dp[i][j-2]-a[j-1],dp[i+1][j-1]-a[i]));
            else dp[i][j]= max(a[i]-dp[i+1][j],a[j]-dp[i][j-1]);
        }
    }
    cout<<dp[0][n-1]<<"\n";
    return 0;
}

Measured memory_bytes: 70528
#include <iostream>
#include <stdio.h>

using namespace std;

int main() {
  int N, D, X;
  cin >> N >> D >> X;
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    int a;
    cin >> a;
    int j = 1;
    int d = 1;
    while (d <= D) {
      ++cnt;
      d = j++ * a + 1;
    }
  }
  printf("%d\n", cnt + X);
}

Measured memory_bytes: 3152
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <queue>
#include<vector>
#include <algorithm>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    int v[55];
    int ans=-9999999;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
    }
    int a,b,c;
    for(a=0; a<=k; a++)
    {
        for(b=0; b<=k; b++)
        {
            for(c=0; c<=k; c++)
            {
                if(a+b+c<=k&&a+b>=c&&a+b<=n)
                {
                    priority_queue<int>q;
                    for(int i=0; i<a; i++)
                    {
                        q.push(v[i]);
                    }
                    for(int i=0; i<b; i++)
                    {
                        q.push(v[n-i-1]);
                    }
                    int sum=0;
                    for(int i=0; i<a+b-c; i++)
                    {
                        sum+=q.top();
                        q.pop();
                    }
                    ans=max(ans,sum);
                }

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


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

int main() {
  int n,k;
  cin>>n>>k;
  vector<int> a(3);
  rep(i,3) cin >> a[i];
  string s;
  cin>>s;
  vector<int> ctoi(256);
  ctoi['r'] = 2;
  ctoi['c'] = 0;
  ctoi['p'] = 1;
  int ans = 0;
  rep(i,k) {
    vector<int> x;
    for (int j = i; j < n; j += k) {
      x.push_back(ctoi[s[j]]);
    }
    vector<int> dp(2);
    int pre = -1;
    for (int nx : x) {
      vector<int> p(2);
      swap(dp,p);
      dp[0] = max(p[0],p[1]);
      if (pre == nx) {
        dp[1] = p[0]+a[nx];
      } else {
        dp[1] = max(p[0],p[1])+a[nx];
      }
      pre = nx;
    }
    ans += max(dp[0],dp[1]);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1020
#include <iostream>
#include <algorithm>
#include <cmath>
#include <iomanip>

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

int main() {
    double a, b, h, m;
    cin >> a >> b >> h >> m;

    double angle = abs((h * 30) + (m * 0.5) - (m * 6));
    double pi = acos(-1);

    double dis = powl(a, 2) + powl(b, 2) - (2 * a * b * cos(angle * (pi/180)));
    double ans = sqrtl(dis);

    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
const long long maxn=1e4+10;
const long long inf=1e15;
void in(long long &x){
    long long y=1;char c=getchar();x=0;
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){ x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    x*=y;
}
void o(long long x) {
    if (x < 0){
        putchar('-');
        x = -x;
    }
    if (x > 9)o(x / 10);
    putchar(x % 10 + '0');
}
long long read(){
    long long  res=0;
    long long  y=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c<='9'&&c>='0'){res=(res<<1)+(res<<3)+c-'0';c=getchar();}
    return res*y;
}

long long X,Y,A,B,C;
vector<long long>vx,vy,vc,vv;
bool cmp(long long x,long long y){
    return x>y;
}
signed main(){
    in(A);in(B);in(X);in(Y);in(C);
    for(long long i=1;i<=X;i++){vx.push_back(read());}
    for(long long i=1;i<=Y;i++){vy.push_back(read());}
    for(long long i=1;i<=C;i++){vc.push_back(read());}
    sort(vx.begin(),vx.end(),cmp);
    sort(vy.begin(),vy.end(),cmp);
    sort(vc.begin(),vc.end(),cmp);
    long long pa=A-1,pb=B-1,pc=0,ans=0;
    for(long long i=0;i<=pa&&i<vx.size();i++){
        ans+=vx[i];
        vv.push_back(vx[i]);
    }
    if(pa>=vx.size()){
        for(long long i=0;i<A-vx.size();i++){
            ans+=vc[i];
            pc++;
        }
    }
    for(long long i=0;i<=pb&&i<vy.size();i++){
        ans+=vy[i];
        vv.push_back(vy[i]);
    }
    if(pb>=vy.size()){
        for(long long i=pc;i<B-vy.size()+pc;i++){
            ans+=vc[i];
            pc++;
        }
    }
    sort(vv.begin(),vv.end(),cmp);
    long long pvv=vv.size()-1;
    while(pc<vc.size()&&0<=pvv&&vv[pvv]<vc[pc]){
        ans-=vv[pvv];
        ans+=vc[pc];
        pvv--;
        pc++;
    }
    o(ans);putchar('\n');
    return 0;
}


/*struct edge{
    long long to,next,value;
}e[maxn];
long long first[maxn]={0},cntedge=0;
void addedge(long long fr,long long to,long long value){
    e[cntedge++]={to,first[fr],value};first[fr]=cntedge-1;
    swap(fr,to);
    e[cntedge++]={to,first[fr],0};first[fr]=cntedge-1;
}*/


Measured memory_bytes: 7616
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr int Inf = 1000000001;
constexpr ll INF= 1e18;
constexpr ll MOD = 1000000007;
const double PI = 3.1415926535897;
typedef pair<int,int> P;

int main() {
    int N;
    cin >> N;
    vector<tuple<int,int,int>> vec(N);
    for(int i = 0;i < N;i++) {
        int A,B,C;
        cin >> A >> B >> C;
        vec.at(i) = make_tuple(A,B,C);
    }
    int time = 0;
    int x = 0;
    int y = 0;
    bool ret = true;
    for(int i = 0;i < N;i++) {
        int cost = abs(x - get<1>(vec.at(i))) + abs(y - get<2>(vec.at(i)));
        int time2 = get<0>(vec.at(i)) - time;
        if(time2 >= cost && (time2 - cost) % 2 == 0) {

        }
        else {
            ret = false;
        }
    }
    if(ret == true) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 1408
#include <iostream>

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

using namespace std;

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



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

struct TNode
{
	int Id;
	TNode* Parent;
	TNode* LChild;
	TNode* RChild;
};

struct TTree
{
private:
	TNode* Root;
	void Delete(const TNode* Node)
	{
		if(Node == NULL) return;
		Delete(Node->LChild);
		Delete(Node->RChild);
		delete Node;
	}
	void InorderOutput(const TNode* Node)
	{
		if(Node == NULL) return;
		InorderOutput(Node->LChild);
		cout << ' ' << Node->Id;
		InorderOutput(Node->RChild);
	}
	void PreorderOutput(const TNode* Node)
	{
	    if(Node == NULL) return;
	    cout << ' ' << Node->Id;
	    PreorderOutput(Node->LChild);
	    PreorderOutput(Node->RChild);
	}
public:
	TTree()
	{
		Root = NULL;
	}
	~TTree()
	{
		Delete(Root);
	}
	void Insert(TNode* z)
	{
	    assert(z != NULL);
		TNode* y = NULL;
		TNode* x = Root;
		while(x != NULL){
			y = x;
			if(z->Id < x->Id){
				x = x->LChild;
			}else{
				x = x->RChild;
			}
		}
		z->Parent = y;
		if(y == NULL){
			Root = z;
		}else if(z->Id < y->Id){
			y->LChild = z;
		}else{
			y->RChild = z;
		}
	}
	void Print()
	{
		InorderOutput(Root);
		cout << endl;
		PreorderOutput(Root);
		cout << endl;
	}
};

int main()
{
	int n;
	cin >> n;
	TTree Tree;
	for(int i = 0; i < n; i++){
		string Command;
		cin >> Command;
		if(Command == "insert"){
			int Id;
			cin >> Id;
			TNode* Node;
			Node = new TNode;
			*Node = {Id, NULL, NULL, NULL};
			Tree.Insert(Node);
		}else{
			Tree.Print();
		}
	}
    return 0;
}

Measured memory_bytes: 26596
#include <iostream>

using namespace std;

#define mod 1000000007

long long zizyo(long long n){
	return n*n%mod;
}

long long ruizyo(long long n, int m){
	if(m==0)return 1;
	if(m==1)return n;
	if(m%2)return n*zizyo(ruizyo(n,m/2))%mod;
	return zizyo(ruizyo(n,m/2));
}


int main(){
	int H,W,A,B;
	cin >> H >> W >> A >> B;
	long long  a[200001],b[200001];
	a[0]=1;
	a[1]=1;
	for(int i=2;i<=H+W;i++){
		a[i] = a[i-1]*i%mod;
	}
	b[H+W]=ruizyo(a[H+W],mod-2);
	for(int j=H+W-1;j>=0;j--){
		b[j] = b[j+1]*(j+1)%mod;
	}
	long long ans,tmp;
	ans =0;
	for(int k=B;k<W;k++){
		tmp = a[H-A-1+k]*a[W-k+A-2]%mod;
		tmp = tmp*b[H-A-1]%mod;
		tmp = tmp*b[k]%mod;
		tmp = tmp*b[W-k-1]%mod;
		tmp = tmp*b[A-1]%mod;
		ans = (ans+tmp)%mod;
	}
	cout << ans << endl;
	return 0;
}

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

int H[100000];
bool down[100000] = {false};

void Main()
{
  int N;
  cin >> N;
  rep(i,N) {
    cin >> H[i];
  }
  rep(i,N-1) {
    if (H[i] - H[i+1] > 1) {cout << "No" << endl; return;}
    else if (H[i] - H[i+1] == 1) {
      H[i]--;
      down[i] = true;
    }
  }
  rep(i,N-1){
    //cout << H[i] << "," << H[i+1] << endl;
    if (H[i] - H[i+1] > 1){cout << "No" << endl; return;}
    else if (H[i] - 1 == H[i+1]) {
      if (!down[i]) {
        down[i] = true; H[i]--;
        i = -1;
      } else {cout << "No" << endl; return;}
    }
  }
  cout << "Yes" << endl;
}

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


Measured memory_bytes: 768
#include <bits/stdc++.h>
    using namespace std;
    
    int main(){
        string a , b , c;
        cin >> a >> b >> c;
        if( a[a.length()-1] == b[0] && b[b.length()-1] == c[0]){
            cout << "YES" << endl;
        }else{
            cout << "NO" << endl;
        }
        
        return 0;
    }

Measured memory_bytes: 256
import bisect
INF=10**100

A,B,Q,*stx,=open(0).read().split()
A,B,Q=map(int,[A,B,Q])
slist=[-INF]+[int(stx[i]) for i in range(A)]+[INF]
tlist=[-INF]+[int(stx[i]) for i in range(A,A+B)]+[INF]
xlist=[int(stx[i]) for i in range(A+B,A+B+Q)]
oslist=[0]*2
otlist=[0]*2
sr_index=0
tr_index=0
for i in xlist:
    ans=INF
    sr_index=bisect.bisect_left(slist,i)
    oslist=[slist[sr_index-1],slist[sr_index]]
    tr_index=bisect.bisect_left(tlist,i)
    otlist=[tlist[tr_index-1],tlist[tr_index]]
    for j in oslist:
        for k in otlist:
            ans=min(ans,abs(j-i)+abs(k-j),abs(k-i)+abs(j-k))
    print(ans)

Measured memory_bytes: 44220
package main

import (
  "fmt"
)

func pow(args ...int) int {
  x, y := args[0], args[1]
  res := 1
  if len(args) == 3 {
    mod := args[2]
    for y != 0 {
      if y & 1 == 1 {res = res * x % mod}
      y >>= 1
      x = x * x % mod
    }
  }  else {
    for y != 0 {
      if y & 1 == 1 {res *= x}
      y >>= 1
      x *= x
    }
  }
  return res
}

func main() {
  var n, k int 
  fmt.Scan(&n, &k)
  fmt.Println(k * pow(k-1, n-1))

}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
#define p 1000000007
int maxn= 400010;
int a[400010], f[400010], n, m;
int main()
{
    ll n, m;
    ll x;
     cin >> n >> m;
  for (int i = 1, x; i <= m; i++) {
    cin >> x, a[x] = 1;
  }
  f[0] = 1;
  for (int i = 1; i <= n; i++) {
    f[i] = (f[i - 1] + f[i - 2]) % p;
    if (a[i])
      f[i] = 0;
  }
  cout << f[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
/*The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

//PRABHJOT SINGH A.K.A. PRABHI
//~~~~~conquizztador~~~~~


#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n=0,a=0,b=0,ct1=0,ct2=0,ct3=0;
    cin>>n;
    cin>>a>>b;
    vector<int> p(n);
    for(auto &i: p)
    	cin>>i;
    for(int i=0;i<n;++i)
    {
    	if(p[i]<=a)
    		++ct1;
    	else if(p[i]<=b)
    		++ct2;
    	else
    		++ct3;
    }
    cout<<min({ct1,ct2,ct3})<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
typedef pair<int,int> pii;
vector<pair<int,pii> > vv;
set<int> ls;
int n;
int xx1,yy1,xx2,yy2;
int main(){
    scanf("%d",&n);
    for(int i = 0;i < n;++i ){
        scanf("%d%d%d%d",&xx1,&yy1,&xx2,&yy2);
        if(yy1 == yy2){
            vv.push_back(make_pair(min(xx1,xx2),pii(-inf,yy1)));
            vv.push_back(make_pair(max(xx1,xx2),pii(inf,yy2)));
        }else if(xx1 == xx2){
            vv.push_back(make_pair(xx1,pii(min(yy1,yy2),max(yy1,yy2))));
        }
    }
    sort(vv.begin(),vv.end());
    int ans = 0;
    for(int i = 0;i < vv.size();++i ){
        int tmp2 = vv[i].second.first;
        int tmp3 = vv[i].second.second;
        if(tmp2 == -inf){
            ls.insert(tmp3);
        }else if(tmp2 == inf){
            ls.erase(tmp3);
        }else{
            ans += distance(ls.lower_bound(tmp2),ls.upper_bound(tmp3));
        }
    }
    printf("%d\n",ans);
 //   system("pause");
    return 0;
}


Measured memory_bytes: 8044
// Binary_Search.cs

using System;
using System.Collections.Generic;

class Binary_Search {
	public static void Main() {

		int n = int.Parse(Console.ReadLine());
		int[] s = new int[n];
		string str = Console.ReadLine();
		string[] num = str.Split();

		for(int i = 0; i < n; i++) {
			s[i] = int.Parse(num[i]);
		}

		int m = int.Parse(Console.ReadLine());
		string str_s = Console.ReadLine();
		string[] num_s = str_s.Split();
		int[] search = new int[m];
		for(int i = 0; i < m; i++) {
			search[i] = int.Parse(num_s[i]);
		}

		int count = 0;

		for(int i = 0; i < m; i++) {
			int r = n, mid, l = 0;
			mid = (r + l) / 2;
			while(l < r) {
				mid = (r + l) / 2;
				if(s[mid] == search[i]) {
					count++;
				//	Console.WriteLine("OK");
					break;
				} else if(s[mid] < search[i]) {
					l = mid + 1;
				} else {
					r = mid;
				}
			}
		}

		Console.WriteLine(count);

	}
}

Measured memory_bytes: 18228
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define vpii vector<pair<int,int>>
#define vv vector<vector<int>>
using namespace std;

string s[26][26];

main()
{
    int h,w; cin>>h>>w;

    rep(i,h)rep(j,w)
    {
        cin>>s[i][j];
        if(s[i][j]=="snuke")
        {
            printf("%c%d\n",'A'+j,i+1);
        }
    }
}


Measured memory_bytes: 256
var input = require('fs').readFileSync('/dev/stdin', 'utf8');

var list = input.split(' ');

var N = Number(list[0]);

var A = Number(list[1]);

var B = Number(list[2]);

var output = () => {
  if (A + B <= N) {
    if (A < B) {
      console.log(`${A} 0`);
      return;
    } else if(A > B) {
      console.log(`${B} 0`);
      return;
    } else {
      console.log(`${A} 0`);
      return;
    }
  } else {
    if (A < B) {
      console.log(`${A} ${A + B - N}`);
      return;
    } else if (A > B) {
      console.log(`${B} ${A + B - N}`);
      return;
    } else {
      console.log(`${A} ${A + B - N}`);
    }
  }
}

output();


Measured memory_bytes: 7372
#include<stdio.h>
#define MAX 100001
 
int main(){
  int i,A[MAX],n,p;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  p=Partition(A,0,n-1);
  for(i=0;i<n-1;i++){
    if(i==p)printf("[");
    printf("%d",A[i]);
    if(i==p)printf("]");
    printf(" ");
  }
  printf("%d\n",A[i]);
  return 0;
}
 
int Partition(int A[],int p, int r){
  int x,i,j,atai;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      atai=A[i];
      A[i]=A[j];
      A[j]=atai;
    }
  }
  atai=A[i+1];
  A[i+1]=A[r];
  A[r]=atai;
  return i+1;
}

Measured memory_bytes: 992
ar = [0 for a in range(10001)]
for a in range(1,100):
    for b in range(1,100):
        for c in range(1,100):
            if a*a + b*b + c*c +a*b + b*c + c*a <=10**4:
                ar[a*a + b*b + c*c +a*b + b*c + c*a]+=1

n = int(input())
for i in range(1,n+1):
    print(ar[i],end= " ")

Measured memory_bytes: 9396
#include <bits/stdc++.h>
using namespace std;
#define int long long
inline void read (int &x) {
    char ch = getchar(); int f = 0; x = 0;
    while (!isdigit(ch)) { if (ch == '-') f = 1; ch = getchar(); }
    while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar(); if (f) x = -x;
} const int N = 1e5 + 10;
int n, a[N], sum, s[N], res[N], mx[N];
signed main() {
    read (n);
    for (int i = 0; i <= n; ++i) read (a[i]); 
    for (int i = n; i >= 0; --i)	 s[i] = s[i + 1] + a[i];
    if (n == 0) { a[0] == 1 ? puts ("1") : puts ("-1"); return 0; }
    res[0] = 1 - a[0], sum = 1;
    for (int i = 1; i <= n; ++i) {
    	res[i] = min (res[i - 1] * 2, s[i]);
		sum += res[i], res[i] -= a[i];
		if (res[i] < 0) return puts ("-1"), 0;
	} return printf ("%lld\n", sum), 0;
}


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

int main()
{
  int kth;
  int numarray[]
  = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  cin >> kth;
  cout << numarray[kth - 1] << endl;

}


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

const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;

vector<P>v[20];

int main(){
	int n;cin>>n;
	rep(i,n){
		int a;scanf("%d",&a);
		rep(j,a){
			int x,y;scanf("%d%d",&x,&y);x--;
			v[i].push_back(P(x,y));
		}
	}
	int ans=0;
	rep(i,1<<n){
		bool ok=true;
		rep(j,n){
			if(!(i>>j&1))continue;
			for(auto p:v[j]){
				if((i>>p.first&1)!=p.second){
					ok=false;break;
				}
			}
		}
		if(ok)ans=max(ans,__builtin_popcount(i));
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
	static boolean bElapsed = false;
	List<String> list = new ArrayList<>();
	Set<String> set = new HashSet<>();
	Map<String,String> map = new HashMap<>();

	int[] cnt = new int[26];

	void solve(BufferedReader br) throws Exception {
		String line = br.readLine();
		for (int i=0; i<line.length(); i++) {
			char ch = line.charAt(i);
			cnt[ch-'a']++;
		}
		String rc = "Yes";
		for (int i=0; i<26; i++) {
			if (cnt[i] % 2 > 0) {
				rc = "No";
				break;
			}
		}
		pln(rc);
	}

	void p(char c) {
		System.out.print(c);
	}
	void pln(char c) {
		System.out.println(c);
	}
	void p(long l) {
		System.out.print(l);
	}
	void pln(long l) {
		System.out.println(l);
	}
	void p(String s) {
		System.out.print(s);
	}
	void pln(String s) {
		System.out.println(s);
	}
	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		new Main().solve(br);
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.out.println((end-start) + "ms");
		}
	}
}


Measured memory_bytes: 8276
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){

    while(true){
        int N,x;cin >> N >> x;
        
        if(N == 0 && x == 0)break;

        int ct = 0;
        for(int i = 1;i <= N;++i){
            for(int j = i+1;j <= N;++j){
                for(int k = j+1;k <= N;++k){
                    if(i + j + k == x)ct++;
                }
            }
        }

        cout << ct << endl;
    };

}



Measured memory_bytes: 3096
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.Array.Unboxed
import Data.Bits
import Data.List
import qualified  Data.ByteString as B
import Data.Ord
import Data.Array.ST
-- import Data.Array.IO 
import Control.Monad.ST
import Data.List.Extra


bsToInt :: BS.ByteString -> Int
bsToInt = fst . fromJust . BS.readInt

bsToIntList :: BS.ByteString -> [Int]
bsToIntList = map bsToInt . BS.words

main :: IO ()
main = do
    s:w:_ <- bsToIntList <$> BS.getLine
    putStr $ if s<=w then "unsafe" else "safe"

Measured memory_bytes: 3756
//Δ_E
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 1<<20;
const int MO = 1e9+7;
int n,m,a[N],b[N],s[N];
vector<int> v[N];
int cal(int o,int f=0){
	int i,j,x,y;
	x=1,y=0;
	for(i=0;i<v[o].size();i=i+1){
		j=v[o][i];
		y=(y+x)%MO;
		if(i+1<v[o].size())
			x=(x+(LL)y*(s[v[o][i+1]]-s[j])%MO)%MO;
	}
	if(f)
		return x;
	return y;
}
int main()
{
	int i,x,o;
	scanf("%d",&n);
	for(i=1;i<=n;i=i+1){
		scanf("%d",a+i);
		m^=a[i];
		b[i]=b[i-1]^a[i];
		s[i]=s[i-1];
		if(!b[i])
			s[i]++;
	}
	for(i=1;i<n;i=i+1)
		v[b[i]].push_back(i);
	if(m){
		v[m].push_back(n);
		cout<<cal(m,1);
		return 0;
	}
	x=0;
	for(i=1;i<N;i=i+1)
		x=(x+cal(i))%MO;
	o=1;
	for(i=1;i<=s[n-1];i=i+1)
		o=o*2%MO;
	cout<<(x+o)%MO;
	return 0;
}

Measured memory_bytes: 40564
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
const ll MODA=998244353;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        swap(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
vector<ll> find_divisor(ll N){
  ll k=1;
  while(k*k<=N){
    k++;
  }
  vector<ll> A(1);
  rep(i,k){
    if(i==1)A.at(0)=1;
    else if(i>=2){
      if(N%i==0)A.push_back(i);
    }
  }
  ll t=0;
  t=A.size();
  rep(i,t){
    if(A.at(t-i-1)*A.at(t-i-1)!=N)A.push_back(N/A.at(t-1-i));
  }
  return A;
}
vector<ll> fac;
vector<ll> finv;
vector<ll> inv;
void COMinit(ll N,ll P){
    rep(i,N+1){
        if(i==0){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else if(i==1){
            fac.push_back(1);
            finv.push_back(1);
            inv.push_back(1);
        }
        else{
            fac.push_back(fac.at(i-1)*i%P);
            inv.push_back(P-inv.at(P%i)*(P/i)%P);
            finv.push_back(finv.at(i-1)*inv.at(i)%P);
        }
    }
}

ll COM(ll n,ll k,ll P){
    if(n<k)return 0;
    if(n<0||k<0)return 0;
    return fac.at(n)*(finv.at(k)*finv.at(n-k)%P)%P;
}
int main()
{
    ll D,S,T;
    cin>>D>>T>>S;
    if(D<=S*T)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
fn main() {
    let v = read::<String>()
        .chars()
        .map(|c| c as i32 - 48)
        .collect::<Vec<_>>();
    for i in 0..1 << 3 {
        let mut a = v[0];
        for j in 0..3 {
            if (1 << j) & i == 0 {
                a -= v[j + 1];
            } else {
                a += v[j + 1];
            }
        }
        if a == 7 {
            let mut op = vec!['+'; 3];
            for j in 0..3 {
                if (1 << j) & i == 0 {
                    op[j] = '-';
                }
            }
            println!(
                "{}{}{}{}{}{}{}=7",
                v[0], op[0], v[1], op[1], v[2], op[2], v[3]
            );
            break;
        }
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, q;
    cin >> n >> k >> q;
    vector<int> p(n);
    rep (i, q) {
        int a;
        cin >> a;
        p[a - 1]++;
    }
    rep (i, n) {
        int point = k - q + p[i];
        if (point <= 0) {
            cout << "No" << endl;
        } else {
            cout << "Yes" << endl;
        }
    }
    
    return 0;
}



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

int main()
{
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    if(a[0] != 0)
    {
        cout << -1 << endl;
        return 0;
    }

    a.push_back(0);
    ll ans = 0;
    for(int i = n-1; i >= 0; i--)
    {
        if(a[i] == a[i+1] - 1) continue;
        else if(a[i] < a[i+1] - 1)
        {
            cout << -1 << endl;
            return 0;
        }
        else
        {
            ans += a[i];
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define N 100005

using namespace std;
int INF = 1e9;
typedef pair<int,int> ii;
vector<int> AdjList[N];
priority_queue<ii,vector<ii>,greater<ii>> pq;

signed main()
{
    int n;
    cin>>n;
    int ans[n+1];

    for(int i=1;i<=n;i++)
        ans[i] = INF;

    for(int i=1;i<n;i++)
    {
        int u,v;
        cin>>u>>v;
        AdjList[u].push_back(v);
        AdjList[v].push_back(u);
    }

    int m;
    cin>>m;

    for(int i=1;i<=m;i++)
    {
        int u,c;
        cin>>u>>c;
        ans[u] = c;
        pq.push(ii(c,u));
    }

    while(!pq.empty())
    {
        int u = pq.top().second;
        int c = pq.top().first;
        pq.pop();

        for(int v:AdjList[u])
        {
            if(ans[v]==INF)
            {
                ans[v] = ans[u] + 1;
                pq.push(ii(ans[v],v));
            }
            else
            {
                if(abs(ans[u]-ans[v])!=1)
                {
                    cout<<"No";
                    return 0;
                }
            }
        }
    }

    cout<<"Yes\n";
    for(int i=1;i<=n;i++)
        cout<<ans[i]<<'\n';


}


Measured memory_bytes: 7924
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
typedef long long int ll;
 
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

 
 
const ll N = 200005;
const ll mod = 1000000007;
const long long int inf = 1e10+5;
#define pp pair<ll,ll>
 
typedef long double ld;
typedef vector<pp> vpl;
#define MP make_pair
#define endl "\n"
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<n;i++)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define repb(i,n) for(ll i=1;i<n-1;i++) 
#define trace(i,a) for(auto i=a.begin();i!=a.end();i++) 
#define mtrace(i,a) for(auto i=a.begin();i!=a.end();i++)  cout<<i->first<<" "<<i->second<<endl;   




void fastIO(void);
void decimal(int);
ll modmulti(ll, ll);
ll modadd(ll, ll);
ll modpower(ll, ll);
ll gcd(ll, ll );
ll modinv(ll);




int main(){
    
     
   ordered_set s;
   ll n;
   cin>>n;
   ll a[n];
   rep(i,n) cin>>a[i];
   ll cnt = 0;
   rep(i,n){
       if(s.order_of_key(N)-s.order_of_key(a[i])==i){ cnt++; }
       s.insert(a[i]);
   }
   cout<<cnt<<endl;






   

}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
void fastIO(void)
{  ios_base::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
}
 
void decimal(int n){
   cout<<fixed;
   cout<<setprecision(n);
}
ll modmulti(ll a, ll b){
   return ((a%mod)*1ll*(b%mod))%mod;
}
ll modadd(ll a, ll b){
   ll asdfgh =  ((a%mod)+(b%mod)+mod+mod)%mod;
   asdfgh = (asdfgh+mod)%mod;
   return asdfgh;
}
ll modpower(ll a, ll n){
   if(n==0) return 1;
   if(n==1) return a%mod;
   ll b = modpower(a,n/2);
   b = modmulti(b,b);
   if(n%2==0) return b;
   return modmulti(a,b);
}
ll gcd(ll a, ll b){
   if(b==0)
      return a;
   return gcd(b,a%b);
}
ll modinv(ll a){
   return modpower(a,mod-2);
}
 

Measured memory_bytes: 14720
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    S=ST()
    T=ST()
    ans = 2*N
    for i in range(1,N+1): # 何文字被るか
        if(S[-i:] == T[:i]):
            ans = min(ans, 2*N-i)
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 5332
class BIT():
    def __init__(self,size):
        self.size=size
        self.node=[0]*(size+1)

    def sum(self,idx):
        ret=0
        while idx>0:
            ret+=self.node[idx]
            idx-=idx&(-idx)
        return ret

    def add(self,idx,x):
        while idx<=self.size:
            self.node[idx]+=x
            idx+=idx&(-idx)

n,m=map(int,raw_input().split())
L=[[] for _ in xrange(m+1)]
for i in xrange(n):
    l,r=map(int,raw_input().split())
    r+=1
    L[r-l].append(l)
bit=BIT(m+1)
total=0
for d in xrange(1,m+1):
    for l in L[d]:
        r=l+d
        bit.add(l,1)
        bit.add(r,-1)
    total+=len(L[d])
    ans=n-total
    now=0
    while now<=m:
        ans+=bit.sum(now)
        now+=d
    print(ans)

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

int main(){
  int a;
  cin >> a;
  vector<int> s(a);
  for(int i = 0;i<a;i++){
    int b;
    cin >> b;
    s.at(i) = b;
  }
  int c;
  cin >> c;
  vector<int> ss(a);
  for(int i = 0; i<c;i++){
    ss = s;
    int d,e;
    cin >> d >> e;
    ss.at(d-1) = e;
    int sum = 0;
    for(int j = 0;j<a;j++)
      sum += ss.at(j);
    cout << sum << endl;
  }
}
  


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

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;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
//#define int long long

signed main() {
    int n;
    cin >> n;
    string s;
    map<string, int> m;
    rep(i, n) {
        cin >> s;
        m[s]++;
    }
    cout << "AC x " << m["AC"] << endl;
    cout << "WA x " << m["WA"] << endl;
    cout << "TLE x " << m["TLE"] << endl;
    cout << "RE x " << m["RE"] << endl;
}

Measured memory_bytes: 3628
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=2e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,m,x[1005]={},y[1005]={},z[1005]={},a[1005]={},ans=0,cnt;
  cin >> n >> m;
  for(int i=0; i<n; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }
  for(int i=0; i<(1<<3); i++) {
    for(int j=0; j<n; j++) {
      cnt=0;
      a[j]=x[j]*(1&i?1:-1)+y[j]*(2&i?1:-1)+z[j]*(4&i?1:-1);
    }
    sort(a,a+n,greater<ll>());
    for(int j=0; j<m; j++) {
      cnt+=a[j];
    }
    ans=max(ans,cnt);
  }
  cout << ans << endl;
}


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

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key % M; }
int h2(int key){ return 1 + (key % (M-1)); }

int find(char str[]){
  int key = getKey(str), j, i = 0;
  for(;;){
    j = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[j], str) == 0)
      return 1;
    else if(H[j][0] == '\0' || i >= M)
      return 0;
    else i++;
  }
}

void insert(char str[]){
  int i = 0, j, key = getKey(str);
  do {
    j = (h1(key) + i * h2(key)) % M;
    i++;
  } while (H[j][0] != '\0');
  for(i = 0; i < strlen(str); i++) H[j][i] = str[i];
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}

Measured memory_bytes: 15416
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k ,x, y;
  cin >> n >> k >> x >> y;
  
  int sum = 0;
  if (n <= k) {
    sum = n * x;
  }
  
  if (n > k) {
    sum = (k * x) + ((n - k) * y);
  }
  
  cout << sum << endl;
  
}
 

Measured memory_bytes: 3564
#include<iostream>

using namespace std;

int h, w;
int map[90][90];

int vx[4] = { 0,1,0,-1 }, vy[4] = { 1,0,-1,0 };

int dfs(int i, int j, int cnt) {
	map[i][j] = 0;
	int ret = cnt + 1;
	for (int a = 0; a < 4; a++) {
		int ni = i + vx[a], nj = j + vy[a];
		if (ni < 0 || nj < 0 || ni >= h || nj >= w)continue;
		if (map[ni][nj] == 0)continue;
		int tmp = dfs(ni, nj, cnt + 1);
		if (ret < tmp)ret = tmp;
	}
	map[i][j] = 1;
	return ret;
}

int main() {
	while (true) {
		int ans = 0;
		cin >> w >> h;
		if (w == 0 && h == 0)break;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> map[i][j];
			}
		}
		
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (map[i][j] == 1) {
					int tmp = dfs(i, j, 0);
					if (ans < tmp)ans = tmp;
				}
			}
		}
		
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3120
#import pysnooper
import os,re,sys,operator,math,heapq,string
#from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement
from sys import stdin,setrecursionlimit
#from copy import deepcopy

setrecursionlimit(10**6)
input=stdin.readline

n,c,k=map(int,input().split())
t=sorted([int(input().rstrip()) for _ in range(n)])
ans=0
now=[]
for i in range(n):
    if len(now)==c:
        ans+=1
        now=[t[i]]
    elif now!=[] and now[0]+k<t[i]:
        ans+=1
        now=[t[i]]
    else:
        now.append(t[i])
    #print(now)

print(ans+1)

Measured memory_bytes: 8880
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
typedef vector<ll> vl;
#define rp(i, f, t) for (long long int i = f; i < t; i++)
#define pr(i, f, t) for (long long int i = t - 1; i >= f; i--)
#define ca(n, a) rp(ca_i, 0, n) cout << a[ca_i] << ((ca_i == n - 1) ? "\n" : " ")
#define ia(n, a) rp(ia_i, 0, n) cin >> a[ia_i]
#define za(n, a) rp(za_i, 0, n) a[za_i] = 0
#define be(a) a.begin(), a.end()
#define ce(a) cout << (a) << endl
int main()
{
    ll x, k, d;
    cin >> x >> k >> d;
    x = llabs(x);
    ll ans = inf;
    ll r = x / d;
    if (k % 2 == 0)
    {
        if (k < r)
        {
            ans = min(ans, llabs(x - d * (k)));
        }
        else
        {
            if (r % 2 == 0)
            {
                ans = min(ans, llabs(x - d * r));
                if (r + 2 <= k)
                    ans = min(ans, llabs(x - d * (r + 2)));
            }
            else
            {
                ans = min(ans, llabs(x - d * (r - 1)));
                if (r + 1 <= k)
                    ans = min(ans, llabs(x - d * (r + 1)));
            }
        }
    }
    if (k % 2 == 1)
    {
        if (k < r)
        {
            ans = min(ans, llabs(x - d * k));
        }
        else
        {
            if (r % 2 == 1)
            {
                ans = min(ans, llabs(x - d * r));
                if (r + 2 <= k)
                    ans = min(ans, llabs(x - d * (r + 2)));
            }
            else
            {
                ans = min(ans, llabs(x - d * (r - 1)));
                if (r + 1 <= k)
                    ans = min(ans, llabs(x - d * (r + 1)));
            }
        }
    }
    ce(ans);
}

Measured memory_bytes: 3636