akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
unsigned long long n,k,a[200001],f[200001],m,town=1;
int main()
{
	cin>>n>>k;
	for(int i=2;i<=200000;i++)f[i]=-1;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	while(m<k)
	{
		m++;
		town=a[town];
		if(f[town]!=-1)break;
		f[town]=m;		
	}
	if(m==k)
		cout<<town;
	else 
	{
		n=(k-m)%(m-f[town]);
		for(int i=1;i<=n;i++)
			town=a[town];
		cout<<town;
	}
}


Measured memory_bytes: 6756
n = gets.to_i
R = []
n.times do
  R << gets.to_i
end

maxv = -2000000000
minv = R[0]
i = 1
while i < n
  maxv = [maxv, R[i] - minv].max
  minv = [minv, R[i]].min
  i += 1
end

puts maxv


Measured memory_bytes: 8564
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll p=pow(10,9)+7;
ll phi(ll n) {
    ll result = n;
    for (ll i = 2; i * i <= n; i++) {
        if(n % i == 0) {
            while(n % i == 0)
                n /= i;
            result -= result / i;
        }
    }
    if(n > 1)
        result -= result / n;
    return result;
}
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      
    x = x % p;  
   while (y > 0) 
    { 
        if (y & 1) 
            res = (res*x) % p; 
        y = y>>1; 
        x = (x*x) % p; 
    } 
    return res; 
} 

ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    ll x,n,i,j,k;
    ll ans=0;
    cin>>n>>k;
    ll a=n-k+1;
    ll fact[n+1];
    fact[0]=1;
    fact[1]=1;
    for(i=2;i<=n;i++)
    {
    fact[i]=i*fact[i-1];
    fact[i]%=p;
    }
    for(i=1;i<=k;i++)
    {
        if(a>=i)
        {
        ll ans=(((fact[a]*modInverse(fact[i],p))%p)*(modInverse(fact[a-i],p)))%p;
        ll temp=(((fact[k-1]*modInverse(fact[i-1],p))%p)*(modInverse(fact[k-i],p)))%p;
        ans=(ans*temp)%p;
        cout<<ans<<endl;
        }
        else
        cout<<0<<endl;
    }
}
    


Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val A, B, C = sc.next()
  println {
    A.zip(B).zip(C).map {
      case ((a, b), c) => List(a, b, c).distinct.length - 1
    }.sum
  }
}


Measured memory_bytes: 55664
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
   
  int y;
  
  for (int i = 0; i < N; i++){
    char s;
    cin >> s;
    
     if ( s == 'Y') {
       y += 1;
     }  
   }
 
  if ( y > 0 ) {
     cout << "Four" << endl;
   } 
   else { 
     cout << "Three" << endl;
   }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
 
#define ff                  first
#define ss                  second
#define endl                "\n"
#define loop(i,s,e)         for(int i=s;i<e;i++)
#define int                 long long
#define vi                  vector<int> 
#define S(v)                sort(v.begin(),v.end())
#define RS(v)               sort(v.rbegin(),v.rend())
#define R(v)                reverse(v.begin(),v.end())
#define mxpq(T)             priority_queue <T>
#define mnpq(T)             priority_queue<T,vector<T>,greater<T>>
#define prv(v)              for(auto &x : v)cout << x << " ";
#define piirv(v)            for(auto &x : v)cout << x.ff << " " << x.ss << endl;
#define prvv(v)             for(auto &x : v)for(auto &y : x.ss)cout << y << " ";
#define mp                  make_pair
#define pii                 pair<int,int>
#define mset(a,f)           memset(a , f , sizeof(a))
#define pb                  push_back
#define inf                 INT_MAX
#define INF                 LLONG_MAX
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> oset;
 
const int N = 2e6 + 6;
const int M = 1e9+7;
int A[N];
int pre[N];
int n , m;

inline int mul(int a, int b) { return (a * b) % M; };
inline int add(int a, int b)
{
      int res = a + b;
      if ( res < 0 ) res += M;
      if ( res >= M) res -= M;
      return res;
}

void solve()
{
	int n;
	cin >> n;

	loop(i,0,n)
	{
		cin >> A[i];
		if(i)pre[i] += pre[i-1] + A[i-1];
	}

	int ans = 0;

	loop(i,0,n)
	{
		int a = A[i]%M;
		a = mul(a , pre[i]%M);
		ans = add(ans%M , a%M);
	}

	cout << ans;
}			
 
int32_t main()
{
 
cout<<fixed<<setprecision(16);
 
ios_base:: sync_with_stdio(false);
cin.tie(NULL); cout.tie(NULL);
 	
 
 	int t = 1;
 	// cin >> t;
 	while(t--)solve();
  
}

Measured memory_bytes: 6700
#include <bits/stdc++.h>
 
#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned long long
#define rep(i,n,N) for(ll i=n;i<=N;++i)
#define rap(i,n,N) for(ll i=n;i>=N;--i)
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define ff fi.fi
#define fs fi.se
#define sf se.fi
#define ss se.se
#define lc (id<<1)
#define rc ((id<<1)|1)
#define db(x) cout << ">>>>>> " << #x << " -> " << x << endl;
#define all(x) x.begin(),x.end()
#define pii pair<int,int> 
#define pll pair<ll,ll>
#define piii pair<int,pii>
#define plll pair<ll,pii>
#define piiii pair<pii,pii>
#define psi pair<string,int>
//#define endl "\n"
const int MAX = 1e3+5;
const ll MAX2 = 11;
const ll MOD = 1000000007;
const ll INF = 1e18;
const int dr[]={1,0,-1,0,1,1,-1,-1,0};
const int dc[]={0,1,0,-1,1,-1,1,-1,0};
const double pi = acos(-1);
const double EPS = 1e-9;
const int block = 450;

int n,x;
set<int> s;

int main(){
//	cout<<fixed<<setprecision(15);
//    freopen("output.txt", "r", stdin);
//	freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>n;
    while(n--){
    	cin>>x;s.insert(x);
	}
	cout<<s.size()<<endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    int a,b,c;
    cin >> a >> b >> c;
    if(a*a+b*b==c*c||a*a+c*c==b*b||b*b+c*c==a*a){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
   


 return 0;
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    int N,h[102] = {};
    int ans = 0;
    bool count = false;
    Scd(N);
    Rep(i,N) Scd(h[i]);
    Repe(hi,102,1){
        Rep(ni,N+1){
            if( h[ni] >= hi ){
                if( !count ) ans++;
                count = true;
            }else{
                count = false;
            }
        }
    }

    printf ("%d\n", ans);

    return 0;
}



Measured memory_bytes: 256
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, a, b) for (int i = a; i < (b); i++)
#define FOR(i, n) for (int i = n; i >= 0; i--)
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define ll long long
#define SIZE 100001
#define MOD 1000000007
#define INF 100000000
using namespace std;
 
int main() {
  int a, b;
  cin >> a >> b;
 
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) {
    cout << "Possible" << endl;
  } else
    cout << "Impossible" << endl;
 
  return 0;
}

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

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}
long long slow_mult(long long base, long long exp, long long mod = MOD) {
    long long tot = 0;
    for(;exp > 0;exp >>= 1){
       if((exp & 1) == 1) tot = (tot + base) % mod;
       base = base * 2 % mod;
    }
    return tot;
}

long long dp[200005], arr[200005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n; cin >> n;

    long long cur, tot = 0, prev = 0;

    dp[0] = 1;

    // maybe optimize to colours :ooo

    for(int i = 1; i <= n; ++i){

        cin >> cur;

        if(cur == prev) continue;

        dp[cur] += dp[prev];
        dp[cur] %= MOD;

        prev = cur;

    }

    cout << dp[prev];

    return 0;

}


Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#define fup(i,a,b) for(int i=a;i<=b;i++)
#define fdw(i,a,b) for(int i=a;i>=b;i--)
#define sync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define cl(a) memset(a,0,sizeof(a))
using namespace std;
typedef long long ll;
const int N=1e6+10;
char s[N],s1[N];
int p[N],sum[N],val[30];
bool pre[N],suf[N];
int len;
void manachar()
{
    cl(pre);
    cl(suf);
    int i,j=0;
    s1[j++]='@';s1[j++]='#';
    for(i=0;s[i];i++)
    {
        s1[j++]=s[i];
        s1[j++]='#';
    }
    s1[j]='\0';
    int id=0,mx=0;
    fup(i,1,j-1)
    {
        if(i<mx) p[i]=min(mx-i,p[2*id-i]);
        else p[i]=1;
        while (s1[i+p[i]]==s1[i-p[i]])p[i] ++;
        if (i+p[i]>mx){
            id=i;
            mx=id+p[i];
        }
        if(i-p[i]==0)
        {
            pre[p[i]-2]=true;
        }
        if((i+p[i])==j)
        {
            suf[len+1-p[i]]=true;
        }
    }

}
int main ()
{
    int n,m;
    cin>>n>>m;
    if(n<m)
    {
        cout<<1<<endl;
    }else
    {
        if(n%m==0)
            cout<<n/m<<endl;
        else cout<<n/m+1<<endl;
    }
    return 0;
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define Cout2(x, y) cout << (x) << " " << (y) << endl
#define dump(x) cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i : a)cout << i << " "; puts("");
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = 1e9;
const double pi = acos(-1.0);

int re2(int a, int b) {
	return (a + b) % 10;
}

string re(string s) {
	string ret;
	rep(i, sz(s) - 1)ret += (char)('0' + re2(s[i] - '0', s[i + 1] - '0'));
	return ret;
}

int main() {
	string s;
	while (cin >> s) {
		while (sz(s) > 1)s = re(s);
		Cout(s);
	}
}


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

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

int main(void)
{

  ll a,b,c;
  cin >> a >>b >>c;

  vector<ll> x(3);
  x[0]=a,x[1]=b,x[2]=c;
  sort(x.begin(), x.end());

  if (a%2==0||b%2==0||c%2==0)
   cout << 0<<endl;

  else
   cout << ((x[2]/2+1)-x[2]/2)*x[0]*x[1] <<endl;
 
 return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#define ll long long
#define all(v) v.begin(),v.end()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=a;i>b;i--)
using namespace std;

int main()
{
    fastio
    int x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<"\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <cmath>
#include <limits>
#include <iostream>
#include <assert.h>

#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P1;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<P1,ll> P2;
typedef pair<ll,Pi> P1i;
const ll INF=10000000000000000001;
struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};
struct pos{
	int x,y,sx,sy,total;
};
P1i d[101]={};
int main(){

	int n;
	cin>>n;
	rep(i,n){
		int x,y;
		ll h;
		cin>>x>>y>>h;
		d[i].first=h;
		d[i].second.first=x;
		d[i].second.second=y;
	}
	sort(d,d+n,greater<P1i>());
	rep(i,101){
		rep(j,101){
			ll H=d[0].first+abs(d[0].second.first-i)+abs(j-d[0].second.second);
			int f=0;
			for(int k=1; k<n; k++){
				if(d[k].first==0){
					if(H-abs(d[k].second.first-i)-abs(j-d[k].second.second)>0){
						f=1;
						break;
					}
				}else if(H-abs(d[k].second.first-i)-abs(j-d[k].second.second)!=d[k].first){
					f=1;
					break;
				}
			}
			if(f==0){
				cout<<i<<" "<<j<<" "<<H<<endl;
				return 0;
			}
		}
	}

	return 0;

}




Measured memory_bytes: 256
INF = 10 ** 11
import sys
sys.setrecursionlimit(100000000)

N,M = map(int,input().split())
MOD = M
G = [[] for _ in range(N)]
for _ in range(N - 1):
    x,y = map(int,input().split())
    x -= 1
    y -= 1
    G[x].append(y)
    G[y].append(x)

deg = [0] * N
dp = [None] * N
parents = [0] * N
ans = [0] * N

def dfs(v,p = -1):
    deg[v] = len(G[v])
    res = 1
    dp[v] = [0] * deg[v]
    for i,e in enumerate(G[v]):
        if e == p:
            parents[v] = i
            continue
        dp[v][i] = dfs(e,v)
        res *= dp[v][i] + 1
        res %= MOD
    return res

def bfs(v,res_p = 0,p = -1):
    if p != -1:
        dp[v][parents[v]] = res_p
    dpl = [1]*(deg[v] + 1)
    dpr = [1]*(deg[v] + 1)
    for i in range(deg[v]):
        dpl[i + 1] = dpl[i]*(dp[v][i] + 1)%MOD
    for i in range(deg[v] - 1,-1,-1):
        dpr[i] = dpr[i + 1]*(dp[v][i] + 1)%MOD
    ans[v] = dpr[0]
    for i in range(deg[v]):
        e = G[v][i]
        if e == p:
            continue
        bfs(e,dpl[i]*dpr[i + 1]%MOD,v)

dfs(0)
bfs(0)
print('\n'.join(map(str,ans)))

Measured memory_bytes: 161836
#include <iostream>

int main(){
	int n, a;
	const int c = 500;

	std::cin >> n;
	std::cin >> a;

	if(n % c  <= a){
		std::cout << "Yes" << std::endl;
	}
	else{
		std::cout << "No" << std::endl;
	}

	return 0;
}


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

int main(void) {
	int n, i;
	scanf("%d", &n);
	char *s = malloc(sizeof(char)*(n + 1));
	scanf("%s", s);
	int count = 0;
	for(i = 0; i < n - 2; i++)
		if(*(s + i) == 'A' && *(s + i + 1) == 'B' && *(s + i + 2) == 'C')
			count++;
	free(s);
	printf("%d\n", count);
	return 0;
}

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

const long long N = 1e15;

int s(long long x) {
  int ans = 0;
  while (x > 0) {
    ans += x % 10;
    x /= 10;
  }
  return ans;
}

long long get(long long x) {
  vector<int> d;
  {
    long long tmp = x;
    while (tmp > 0) {
      d.push_back(tmp % 10);
      tmp /= 10;
    }
  }
  long long mt = 1, ans = x;
  double mn = x / (double) s(x);
  for (int i = 0; i < (int) d.size(); ++i, mt *= 10) {
    for (int j = d[i]; j <= 9; ++j) {
      long long cur = x + (j - d[i]) * mt;
      if (cur / (double) s(cur) < mn) {
        ans = cur;
        mn = cur / (double) s(cur);
      }
    }
    x -= d[i] * mt;
    x += 9 * mt;
  }
  return ans;
}

int main() {
  long long n = 1;
  vector<long long> snukes;
  while (n < N) {
    snukes.push_back(n);
    n = get(n + 1);
  }
  int k;
  scanf("%d", &k);
  for (int i = 0; i < k; ++i)
    printf("%lld\n", snukes[i]);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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


int main()
{
	int N,M,X,Y;
	int x=-110,y=110;
	scanf("%d%d%d%d",&N,&M,&X,&Y);
	int a;
	for(int i=0;i<N;i++){
		scanf("%d",&a);
		x = max(x,a);
	}
	for(int i=0;i<M;i++){
		scanf("%d",&a);
		y = min(y,a);
	}
	X++;
	x++;
	bool t = false;
	for(int i=X;i<=Y;i++){
		if(x <= i && i <= y)t = true;
	}
	if(t)puts("No War");
	else puts("War");

	return 0;
}


Measured memory_bytes: 128
N, K, *A = map(int, open(0).read().split())

t = [[-1] * N for _ in range(61)]
t[0] = [A[i] - 1 for i in range(N)]
for k in range(1, 61):
    for i in range(N):
        t[k][i] = t[k - 1][t[k - 1][i]]

u = 0
for k in range(61):
    if K >> k & 1:
        u = t[k][u]

print(u + 1)


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

typedef long long ll;
using namespace std;

int main(void) {
   string S;
   cin>>S;
   ll N = S.size();
   ll ans = 0;
   ll up = 0;
   ll down = 0;
   for (int i = 0;i< N;i++) {
      if (i!=0 && (S[i-1] == '>' && S[i] == '<')) {
         if (down > up) {
            ans += down * (down+1)/2;
            ans += up * (up-1)/2;
         } else {
            ans += up * (up+1)/2;
            ans += down * (down-1)/2;
         }
         up = 0;
         down = 0;
      }
      if (S[i] == '<') {
         up++;
      } else {
         down++;
      }
      if (i==N-1) {
         if (down > up) {
            ans += down * (down+1)/2;
            ans += up * (up-1)/2;
         } else {
            ans += up * (up+1)/2;
            ans += down * (down-1)/2;
         }
         up = 0;
         down = 0;
      }
   }
   cout<<ans<<endl;

   return 0;
}

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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}
//long long int ruizyo(long long int aa, long long int bb){
  //  if(aa==0){
    //    return 1;
    //}
    //else if(aa%2==0){
      //  long long int tt=ruizyo(aa/2,bb);
        //return (tt*tt)%MOD;
    //}
    //else{
      //  return (ruizyo(aa-1,bb)*bb)%MOD;
    //}
//}フェルマ－のア


//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,d,cmp=0,cmpp=0,m,h,w,x[10000000],y[10000000],sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=true;

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

       cin >> n >> m;
       rrep(i,1,n+1)cin>>x[i];
       rrep(j,1,m+1)cin>>y[j];
      rrep(k,1,n+1){
          cmp+=(k-1)*x[k]-(n-k)*x[k];
          cmp%=MOD;
      }
      rrep(k,1,m+1){
          cmpp+=(k-1)*y[k]-(m-k)*y[k];
          cmpp%=MOD;
      }
      Cout(cmp*cmpp%MOD);
       
return 0;
}


Measured memory_bytes: 3072
import sys
from collections import deque

n = int(input())
matches = [[a - 1 for a in map(int, line.split())] for line in sys.stdin]
q = deque(range(n))
depth = [0] * n
waiting = [-1] * n

while q:
    a = q.popleft()
    b = matches[a].pop()
    if waiting[b] == a:
        depth[a] = depth[b] = max(depth[a], depth[b]) + 1
        if matches[a]:
            q.append(a)
        if matches[b]:
            q.append(b)
    else:
        waiting[a] = b

if any(matches):
    print(-1)
else:
    print(max(depth))


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

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

		int n = sc.nextInt(),l = sc.nextInt(),t = sc.nextInt();
		int temp,cnt = 0,d;
		int[] a = new int[n];

		for(int i = 0;i < n;i++){
			a[i] = sc.nextInt();
			d = sc.nextInt();

			if(d == 1){
				temp = a[i] + t;
				a[i] = temp % l;
				cnt += temp / l;
			}else{
				temp = a[i] - t;
				a[i] = temp % l;
				cnt += temp / l;
				if(a[i] < 0){
					a[i] += l;
					cnt--;
				}
			}
		}

		Arrays.sort(a);

		cnt %= n;
		if(cnt < 0)cnt += n;
		cnt %= n;
		for(int i = cnt;i < cnt + n;i++){
			int j = i % n;
			System.out.println(a[j]);
		}

		sc.close();
	}
}

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

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

using namespace std;

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

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

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

static const long long mod = 1000000007;

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

  double r;
  cin >> r;

  r *= (2 * M_PI);

  cout << r << endl;
  return 0;
};


Measured memory_bytes: 3804
# 位置i から左にある黒の数と右にある白の数の合計を調べ、最小となる i を求める
N = gets.to_i
S = gets.chomp.chars # chars は Enumerable に変換

# 位置i の左にある黒の数を累積和にする
lb = []
lb[0] = 0
N.times{|i|
	lb[i+1] = lb[i] + 1 if S[i] == '#'
	lb[i+1] = lb[i] if S[i] != '#'
}

#p lb
# ##### --> 0,1,2,3,4,5
# ...## --> 0,0,0,0,1,2

# S を反転して、反転した状態で
# 位置i の左にある白の数を累積和にする
SR = S.reverse
lw = []
lw[0] = 0
N.times{|i|
	lw[i+1] = lw[i] + 1 if SR[i] == '.'
	lw[i+1] = lw[i] if SR[i] != '.'
}
#作成した累積和を反転する
rw = lw.reverse

#p rw
# ##### --> 0,0,0,0,0,0
# ...## --> 3,2,1,0,0,0

ca = [] #計算結果
(N+1).times{|i|
	ca[i] = lb[i]+rw[i]
}

puts ca.min


Measured memory_bytes: 24828
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;



int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	rep(i, 1, 3500)
	{
		rep(j, 1, 3500)
		{
			int x = n * i * j;
			int y = 4 * i * j - n * i - n * j;
			if (y > 0 && x % y == 0 && x / y <= 3500)
			{
				cout << i << " " << j << " " << x / y << en;
				return 0;
			}
		}
	}


	return 0;
}



Measured memory_bytes: 3496
#include<iostream>
#include<cstdio>
#include<cstring>
int main()
{
	using namespace std;
	char s[10],t[10];
	char u[10];
	int a,b;
	int i;
	cin>>s;
	cin>>t;
	cin>>a>>b;
	cin>>u;
	if(strcmp(s,u)==0)
	a--;
	else
	b--;
	cout<<a<<" "<<b;
	
}

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

int main() {
  ll H, W;
  cin >> H >> W;
  if (H == 1 || W == 1) {
    cout << 1 << endl;  
  } else {
    cout << (H * W + 1) / 2 << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
      return Array.new(size1){init}
  else
      return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

def exc(x)
    case x
      when "Vacant" then
          return 0
      when "Male" then
          return 1
      when "Female" then
          return 2
    end
end
N=gets.to_i
seat=array(N,-1)
puts 0
STDOUT.flush
seat[0]=exc(gets.chomp)
exit if seat[0].zero?
puts N-1
STDOUT.flush
seat[N-1]=exc(gets.chomp)
exit if seat[N-1].zero?
head=0
tail=N-1
20.times do
    if tail-head<=1
        if tail<N/2
            head=N/2+1
            tail=N-1
        else
            head=0
            tail=N/2
        end
    end
    mid=(head+tail)/2
    puts mid
STDOUT.flush
    seat[mid]=exc(gets.chomp)
    break if seat[mid].zero?
    if (seat[mid]==seat[head] and (mid-head).odd?) or (seat[mid]!=seat[head] and (mid-head).even?)
        tail=mid
    else
        head=mid
    end
end

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

int main(){
    ll n,x;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>x;
        a[x-1]=i+1;
    }
    rep(i,n){
        cout<<a[i];
        if(i<n-1){
            cout<<" ";
        }
    }
}

Measured memory_bytes: 4008
//abc163_a.cpp
//Sun Apr 19 20:58:01 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

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

int main(){
	double r;
	cin >> r;
	double PI=3.1415926535897932;

	double ans = 2*r*PI;

	printf("%.10f\n",ans);
}

Measured memory_bytes: 3764
#include <stdio.h>

int main(){
  int N;
  int A[1000];
  int i,j,v;

  scanf("%d", &N);
  for ( i = 0; i < N; i++) {
    /* code */
    scanf("%d", &A[i]);
  }
  for (i = 0; i < N; i++)
    {
        if (i == N - 1){
            printf("%d\n", A[i]);
        }
        else printf("%d ", A[i]);
    }
  for ( i = 1; i <= N-1; i++) {
    /* code */
    v=A[i];
    j=i-1;
    while (j>=0 && A[j]>v) {
      /* code */
      A[j+1] = A[j];
       j--;
      A[j+1] = v;
    }
    //表示
    for ( j = 0; j < N; j++) {
      /* code */
      if(j == N-1){printf("%d\n",A[j]);
      }else{
        printf("%d ", A[j]);
     }
    }
  }
  return 0;
}



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

int main(void) {
    int N, M;
    std::cin >> N >> M;

    bool* sp2i = new bool[N+1];
    bool* i2ep = new bool[N+1];

    int a, b;
    for(int i =0; i < M; ++i) {
        std::cin >> a >> b;
        if (a == 1) {
            sp2i[b] = true;
        }

        if (b == N) {
            i2ep[a] = true;
        }
    }
    
    std::string msg = "IMPOSSIBLE";
    for(int i =0; i < N+1; ++i) {
        if (sp2i[i] && i2ep[i]) {
            msg = "POSSIBLE";
        }
    }

    std::cout << msg << std::endl;

    return 0;
}

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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vector<ll> a(N);
    rep(i, N) cin >> a[i];
    vector<ll> x(N);
    ll sum=0;
    rep(i, N){
        sum += a[i];
    }
    x[0] = sum;
    rep(i, N){
        if(i%2) x[0] -= 2*a[i];
    }

    rep(i, N-1){
        x[i+1] = 2*a[i] - x[i];
    }
    
    rep(i,N){
        cout << x[i];
        if(i != N-1) cout << " ";
        else cout << endl;
    }
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main() {
	string s; cin >> s;
	for (int i = 0; i < s.length(); i++) {
		if (i % 2 == 0) {
			if (s[i] != 'R' && s[i] != 'U' && s[i] != 'D') {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			if (s[i] != 'L' && s[i] != 'U' && s[i] != 'D') {
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define io ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long int ll;
using namespace std;
int main(){
	io;
	char s[4];
	cin >> s;
	bool f = 0;
	for(int i = 0;i < 3;++i){ 
		if(s[i] == '7'){
			f = 1;
		}
	}
	if(f)
		cout << "Yes";
	else
		cout << "No";
	return 0;
}

Measured memory_bytes: 3608
#include <iostream>

using namespace std;

int main() {
    int a,b,x;
    cin >> a >> b >> x ;
    if (a == x) cout << "YES" << endl;
    else if (a > x) cout << "NO" << endl;
    else if (a < x && a + b >= x) cout << "YES" << endl;
    else cout << "NO" << endl;

   
    return 0;
}
    

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define rrep(i, a, b) for (int i = (a); i < (b); ++i)
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using tl = tuple<ll, ll, ll>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    rep(i, 5) {
        int a; cin>>a;
        if (a == 0) cout<<i + 1<<endl;
    }
}

Measured memory_bytes: 3648
def main():
    K = int(input())
    lunlun_cnt = 0
    x = 1
    answer = 0
    while lunlun_cnt < K:
        x_is_lunlun = True
        str_x = str(x)
        length = len(str_x)
        for d in range(2, length + 1):
            # check per 2 digits
            if abs(int(str_x[d - 2]) - int(str_x[d - 1])) > 1:
                x_is_lunlun = False
                x += 10**(length - d)
                break
        if x_is_lunlun:
            lunlun_cnt += 1
            answer = x
            x += 1
    print(answer)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int N = sc.nextInt();
   int[][] a = new int[10][10];
 
   int ans = 0;
   int tmpa=0;
   int tmpb=0;
   for(int i=1;i<=N;i++)
   {
     tmpa=i;
     tmpb=i;
     tmpa=tmpa%10;
     while(tmpb>=10)
     {
       tmpb/=10;
     }
     a[tmpa][tmpb]++;
   }
   
   for(int i =1; i<=9;i++)
   {
     for(int k =1;k<=9;k++) ans+= a[i][k]*a[k][i];
   }
   System.out.println(ans);
 }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int N;
    cin >> N;
    string s[100000];
    for(int i = 0; i < N; ++i) cin >> s[i];

    set<string> stM;
    set<string> stA;
    set<string> stR;
    set<string> stC;
    set<string> stH;
    for(int i = 0; i < N; ++i){
        if(s[i][0] == 'M') stM.insert(s[i]);
        if(s[i][0] == 'A') stA.insert(s[i]);
        if(s[i][0] == 'R') stR.insert(s[i]);
        if(s[i][0] == 'C') stC.insert(s[i]);
        if(s[i][0] == 'H') stH.insert(s[i]);
    }

    long long ans = 0;
    ans += stM.size() * stA.size() * stR.size();
    ans += stM.size() * stA.size() * stC.size();
    ans += stM.size() * stA.size() * stH.size();
    ans += stM.size() * stR.size() * stC.size();
    ans += stM.size() * stR.size() * stH.size();
    ans += stM.size() * stC.size() * stH.size();

    ans += stA.size() * stR.size() * stC.size();
    ans += stA.size() * stR.size() * stH.size();
    ans += stA.size() * stC.size() * stH.size();

    ans += stR.size() * stC.size() * stH.size();

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


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

int main(){
    int n,m,c; cin >> n >> m >> c;
    vector<int> B(m);
    rep(i,m) cin >> B[i];
    int ans=0;
    rep(i,n){
        int tmp=0;
        rep(j,m){
            int a; cin >> a;
            tmp+=a*B[j];
        }
        if(tmp+c>0) ans++;
    }
    cout << ans << endl;
return 0;
}


Measured memory_bytes: 256
//
// Created by yamunaku on 2019/12/29.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

using ll = long long;
using ld = long double;
using vi = vector<int>;
using mti = vector<vector<int>>;
using vl = vector<ll>;
using mtl = vector<vector<ll>>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
template<typename T>
using heap = priority_queue<T, vector<T>, function<bool(const T, const T)>>;

int main(){
    // CFS;
    double a,b,p,q,r;
    cin >> a >> b >> p >> q >> r;
    CST(10);
    cout << b + (b * p - (b-a)*q) / (q+r) << endl;
    return 0;
}


Measured memory_bytes: 3288
#include<iostream>
#include<algorithm>
#include<assert.h>
using namespace std;
int main(){
	long long x,y,z,k;
	cin>>x>>y>>z>>k;
	long long a[x],b[y],c[z];
	for(long long i=0;i<x;++i)
		cin>>a[i];
	for(long long i=0;i<y;++i)
		cin>>b[i];
	for(long long i=0;i<z;++i)
		cin>>c[i];
	sort(a,a+x,greater<long long>());
	sort(b,b+y,greater<long long>());
	sort(c,c+z,greater<long long>());
	long long t[k*k*3],ti=0;
	for(long long i=0;i<x;++i)
		for(long long j=0;j<y;++j)
			for(long long l=0;l<z;++l){
				if((i+1)*(j+1)*(l+1)<=k){
					t[ti]=a[i]+b[j]+c[l];
					++ti;
					continue;
				}
				break;
			}
	sort(t,t+ti,greater<long long>());
	for(long long i=0;i<k;++i)
		cout<<t[i]<<endl;
	return 0;
}

Measured memory_bytes: 3072
let n = Scanf.scanf " %d" (+) 0
let hs = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let c = ref 0
let _ = Array.fold_left (fun (m, p) h -> if h <= p then incr c else c := 0; max m !c, h) (0, 0) hs |> fst |> Printf.printf "%d\n"

Measured memory_bytes: 5376
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int frog(int h[],int n,int dp[])
{
    if(n==0)
        return 0;
    if(n==1)
        return abs(h[1]-h[0]);
    if(dp[n]!=-1)
        return dp[n];
    int ans =min(frog(h,n-1,dp)+abs(h[n]-h[n-1]),frog(h,n-2,dp)+abs(h[n]-h[n-2]));
    dp[n]=ans;
    return dp[n];
}
int frogBU(int h[],int n,int k)
{
    int dp[n+1]={0};
    dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
    {

        dp[i]=INT_MAX;
        for(int j=1;j<=k && i-j>=0;j++)
        {
            dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
        }
    }
    return dp[n-1];
}
int main()
{
    int n,k;
    cin>>n>>k;
    int h[n+2];
    for(int i=0;i<n;i++)
        cin>>h[i];
    cout<<frogBU(h,n,k);
}


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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
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;
}

//素数判定
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

//桁和
int digsum(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列 -92
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}



int main(){
    int n;
    cin >> n;
    cout << n*n*n << endl;
}

Measured memory_bytes: 256
import itertools
n, m, q = map(int, input().split())

nums_list = []
for i in range(q):
    nums = list(map(int, input().split()))
    nums_list.append(nums)

s_max = 0
for l in list(itertools.combinations_with_replacement(range(1, m+1), n)):
    score = 0
    for nums in nums_list:
        if l[nums[1]-1] - l[nums[0]-1] == nums[2]:
            score += nums[3]
    if score > s_max:
        s_max = score

print(s_max)

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

int main() {
  int N;
  int res;
  cin >> N;
  res = 0;
  
  if(N < 3){
    cout << 0 << endl;
    return 0;
  }

  vector<int> L(N);
  rep(i,N){
    cin >> L.at(i);
  }

  for(int i = 0; i < N-2; i++){
    for(int j = i+1; j < N-1; j++){
      for(int k = j+1; k < N; k++){
        if(L.at(i) + L.at(j) <= L.at(k)) continue;
        if(L.at(j) + L.at(k) <= L.at(i)) continue;
        if(L.at(k) + L.at(i) <= L.at(j)) continue;
		if(L.at(i) == L.at(j)) continue;
        if(L.at(j) == L.at(k)) continue;
        if(L.at(k) == L.at(i)) continue;
        res++;
      }
    }
  }

  cout << res << endl;
  return 0;
}

Measured memory_bytes: 3604
#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 main(){
  int n;
  cin >> n;
  vector<int> ls(n), rs(n);
  rep(i, n) cin >> ls[i] >> rs[i];
  sort(ls.begin(), ls.end());
  sort(rs.begin(), rs.end());
  int ans = 0;
  if (n % 2 == 1){
    int l = ls[n/2];
    int r = rs[n/2];
    ans = r - l + 1;
  }else{
    int l2 = ls[n/2-1] + ls[n/2];
    int r2 = rs[n/2-1] + rs[n/2];
    ans = r2 - l2 + 1;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    string S, T;
    int ans=0;
    cin >> S >> T;

    for(int i=0; i<S.size(); i++){
        if(S.at(i) != T.at(i))
            ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3928
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	n = readline() |> parseInt
	ga,sa,ba = readline() |> split |> parseMap
	gb,sb,bb = readline() |> split |> parseMap
	dp = -ones(Int,n+1)
	dp[1] = n
	for i in 1:n
		if i+ga<=n+1 && dp[i]>-1
			dp[i+ga]=max(dp[i+ga],dp[i]+gb-ga)
		end
	end
	for i in 1:n+1
		if i+sa<=n+1
			if dp[i]>-1
				dp[i+sa]=max(dp[i+sa],dp[i]+sb-sa)
			end
		end
	end
	for i in 1:n+1
		if i+ba<=n+1
			if dp[i]>-1
				dp[i+ba]=max(dp[i+ba],dp[i]+bb-ba)
			end
		end
	end
	m = maximum(dp)
	dp = -ones(Int,m+1)
	dp[1,1] = m
	for i in 1:m
		if i+gb<=m+1 && dp[i]>-1
			dp[i+gb]=max(dp[i+gb],dp[i]+ga-gb)
		end
	end
	for i in 1:m+1
		if i+sb<=m+1
			if dp[i]>-1
				dp[i+sb]=max(dp[i+sb],dp[i]+sa-sb)
			end
		end
	end
	for i in 1:m+1
		if i+bb<=m+1
			if dp[i]>-1
				dp[i+bb]=max(dp[i+bb],dp[i]+ba-bb)
			end
		end
	end

	println(maximum(dp))
end

main()

Measured memory_bytes: 502280
#include <stdio.h>
#include <string.h>
char s[100001];
int a[100001];
int K;
int main(){
  int i,j;
  int len;
  int x;
  scanf("%s",s);
  scanf("%d",&K);
  len=strlen(s);
  for(i=0;i<len;i++){
    a[i]=('z'-s[i]+1)%26;
  }
  //for(i=0;i<len;i++)printf("%d ",a[i]);
  //printf("\n");
  for(i=0;i<len-1;i++){
    if(K>=a[i]){
      s[i]='a';
      K-=a[i];
    }
  }
  x=K%26;
  while(x>0){
    s[i]+=1;
    x--;
    if(s[i]=='z'+1)s[i]='a';
  }
  printf("%s\n",s);
  return 0;
}


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

const int maxn = 200005;
struct SAM{ int p[26], pa, val; } t[maxn];
int tax[maxn], cur[maxn], n, Q, now, v;
int root = 1, size = 1, last = 1;
long long f[maxn], K;
char s[maxn];

void extend(int c) {
	int p = last, np = ++size, q, nq;
	t[np].val = t[p].val + 1;
	for (; p && !t[p].p[c]; p = t[p].pa) t[p].p[c] = np;
	if (!p) t[np].pa = root;
	else {
		q = t[p].p[c];
		if (t[q].val == t[p].val + 1) t[np].pa = q;
		else {
			nq = ++size; t[nq] = t[q];
			t[nq].val = t[p].val + 1;
			t[q].pa = t[np].pa = nq;
			for (; p && t[p].p[c] == q; p = t[p].pa) t[p].p[c] = nq;
		}
	}
	last = np;
}

int main() {
	scanf("%s", &s); n = strlen(s);
	rep (i, 0, n-1)  extend(s[i]-'a');
	rep (i, 1, size) ++tax[t[i].val], f[i] = 1;
	rep (i, 1, size) tax[i] += tax[i-1];
	rep (i, 1, size) cur[size+1-(tax[t[i].val]--)] = i;
	rep (i, 1, size) rep (j, 0, 25) f[cur[i]] += f[t[cur[i]].p[j]];
		scanf("%lld", &K); now = 1;
		while (K) {
			rep (i, 0, 25) if (v = t[now].p[i])
				if (f[v] >= K) { putchar('a'+i); now = v; --K; break; }
				else K -= f[v];
		}
		puts("");
	return 0;
}

Measured memory_bytes: 2432