akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int MAX = 305;
const int NIL = -1;
const ll LINF = 1LL << 50;
const int mod = 1e+9 + 7;
/* global variables */
/* funciton */
/* main */
int main() {
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];


    // sum(a[i], ... , a[j]) = cum[j+1] - cum[i];
    vector<ll> cum(N+2);
    for (int i = 0; i <= N; i++) cum[i+1] = cum[i] + a[i];

    // dp[x][y] = a[x] ~ a[y-1]までを合体させる時の最小コスト
    vector<vector<ll>> dp(N+1, vector<ll>(N+1, LINF));
    for (int i = 0; i < N; i++) { dp[i][i+1] = 0; }
    for (int len = 1; len <= N; len++) {
        for (int x = 0; x <= N - len; x++) {
            int y = x + len;
            for (int z = x + 1; z < y; z++) {
                ll cost = dp[x][z] + dp[z][y] + (cum[z]-cum[x]) + (cum[y] - cum[z]);
                dp[x][y] = min(dp[x][y], cost);
            }
        }
    }

    cout << dp[0][N] << '\n';
}

Measured memory_bytes: 4872
n = int(input())
p = list(map(int, input().split()))

pp = sorted(p)
for i in range(n):
    for j in range(n):
        tmp = p.copy()
        tmpt = tmp[j]
        tmp[j] = tmp[i]
        tmp[i] = tmpt
        if tmp == pp:
            print("YES")
            exit()
print("NO")

Measured memory_bytes: 3060
class COM:
    def __init__(self, n: int, mod: int):
        self.n = n
        self.mod = mod
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]
        
        for i in range(2, n + 1):
            self.fact.append((self.fact[-1] * i) % mod)
            self.inv.append((-self.inv[mod % i] * (mod // i)) % mod)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % mod)
    
    def get_cmb(self, n: int, k: int):
        if (k < 0) or (n < k):
            return 0
        k = min(k, n - k)
        return self.fact[n] * self.factinv[k] % self.mod * self.factinv[n - k] % self.mod


def solve():
    n, k = map(int, input().split())
    MOD = 10 ** 9 + 7
    
    com = COM(n, MOD)
    ans = 0
    for i in range(min(n, k + 1)):
        ans += com.get_cmb(n, i) * com.get_cmb(n - 1, i)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 27092
N = int(input())

s = [[] for _ in range(N)]
for i in range(N):
  A = int(input())
  for _ in range(A):
    x, y = map(int, input().split())
    s[i].append((x - 1, y))

result = 0
for i in range(1, 2 ** N):
  t = [-1] * N
  for j in range(N):
    t[j] = (i >> j) & 1
  m = False
  for j in range(N):
    if (i >> j) & 1 == 0:
      continue
    for x, y in s[j]:
      if t[x] != y:
        m = True
        break
  if not m:
    result = max(result, bin(i)[2:].count('1'))
print(result)


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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << "\n";
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define endl "\n"
// gcj print用
#define Case(x) printf("Case #%d: ", x);

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  while (n > 0) {
    if (n & 1) ret *= x;
    x *= x;
    n >>= 1;
  }
  return ret;
};

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

void print() {
  cout << endl;
}

template <class T>
void print(vector<T> &vec) {
  for (auto& a : vec) {
    cout << a;
    if (&a != &vec.back()) cout << " ";
  }
  cout << endl;
}

template <class T>
void print(vector<T> &vec, ll k){
   ll n = vec.size();
   k = min(k, n);
   rep(i, 0, k-1) cout << vec[i] << " ";
   cout << vec[k-1] << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
  for (auto& vec : df) {
    print(vec);
  }
}

template<class T, class U>
void print(pair<T,U> &p){
  cout << p.first << " " << p.second << "\n";
}

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

  double A, B;
  cin >> A >> B;
  double H, M;
  cin >> H >> M;
  double min = H * 60.0 + M;
  double bx = B * cos(deg2rad(360.0 * M / 60.0 - 90.0));
  double by = B * sin(deg2rad(360.0 * M / 60.0 - 90.0));
  double ax = A * cos(deg2rad(360.0 * (min/(720.0)) - 90.0));
  double ay = A * sin(deg2rad(360.0 * (min/(720.0)) - 90.0));

  double ans = sqrt((ax-bx)*(ax-bx)+(ay-by)*(ay-by));
  Decimal(ans);

  return 0;
};


Measured memory_bytes: 4184
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int N;
vector<int> C;
vector<vector<int>> to;

vector<int> size_of_subtree;
vector<lint> nb_path_not_pass_i;
void dfs_st(int now, int par)
{
    size_of_subtree[now] = 1;
    for (auto nxt : to[now]) if (nxt != par)
    {
        dfs_st(nxt, now);
        size_of_subtree[now] += size_of_subtree[nxt];
        nb_path_not_pass_i[now] += 1LL * size_of_subtree[nxt] * (size_of_subtree[nxt] + 1) / 2;
    }
}

vector<int> nb_invalid;
vector<lint> ret;

void dfs1(int now, int par)
{
    int c = C[now];
    int M = N - nb_invalid[c];
    ret[c] += 1LL * M * (M + 1) / 2 - nb_path_not_pass_i[now] - 1LL * (M - size_of_subtree[now]) * (M - size_of_subtree[now] + 1) / 2;

    int m = nb_invalid[c];
    for (auto nxt : to[now]) if (nxt != par)
    {
        nb_invalid[c] = N - size_of_subtree[nxt];
        dfs1(nxt, now);
    }
    nb_invalid[c] = m + size_of_subtree[now];
}

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

    cin >> N;
    C.resize(N);
    for (auto &c : C)
    {
        cin >> c;
        c--;
    }
    to.resize(N);
    for (int e = 0; e < N - 1; e++)
    {
        int a, b;
        cin >> a >> b;
        a--, b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    size_of_subtree.resize(N);
    nb_path_not_pass_i.resize(N);
    dfs_st(0, -1);
    nb_invalid.assign(N, 0);
    ret.resize(N);
    dfs1(0, -1);
    for (auto x : ret) cout << x << '\n';
}


Measured memory_bytes: 35072
#include<bits/stdc++.h>
#define mov(i,a,b) for(int i = a; i < b; i++)
#define MOD 1000000007
#define INF 1e9+5
typedef long long ll;
using namespace std;
bool isPowerOfTwo(ll n){
	return (ceil(log2(n)) == floor(log2(n)));
}
long long binpow(long long a, long long b){
	long long res = 1;
	while(b>0){
		if(b&1) res *= a;
		a = a*a;
		b >>= 1;
	}
	return res;
}
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
	bool x = false;
	if((a.second*a.first) < b.second*b.first){
		x = true;
	}
    return x;
}
int main(){
	
	ll n,k;
	cin>>n>>k;
	if(n <= 12 && n >= 6) cout<<k/2<<"\n";
	else if(n <= 5) cout<<0<<"\n";
	else cout<<k<<"\n";
	
	
	
	
	
	
	
	
	
}

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

int m[10001] = {} ;

void cal(){
	m[1] = 1 ;
	
	for( int i=2 ; i<10001 ; i++ ){
		if( m[i] == 0 ){
			for( int j=2 ; j*i<10001 ; j++ ){
				m[i*j] = 1 ;
			}
		}
	}
}

int main(){
	
	cal() ;
	
	int n ;
	
	while(1){
		cin >> n ;
		if( cin.eof() ) break ;
		
		int ans = 0 ;
		
		for( int i=1 ; i<=n ; i++ ){
			if( m[i] == m[n-i+1] && m[i] == 0 ) ans++ ;
		}
		
		cout << ans << endl ;
	}
	
return 0 ;
}

Measured memory_bytes: 1200
#include <iostream>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <iomanip>
#include <string.h>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()

typedef long long lint;

using namespace std;

int main(){
  int A[5];
  REP(i,5)cin>>A[i];
  int k=0;
  int ans=9999;
  REP(i,5){
    int temp=0;
    REP(j,5){
      if(j==i)continue;
      temp+=A[j];
      if(temp%10!=0)temp+=10-temp%10;
    }
    temp+=A[i];
    ans=min(ans,temp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  int N;
  cin >> N;
  for(ll i=0;i<N+100;i++)
  {
      if(i*i>N)
      {
        cout << (i-1)*(i-1) << endl;
        return 0;
      }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <tuple>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <functional>
#include <climits>
#include <numeric>
#include <queue>
#include <cmath>
#include <iomanip>
#include <array>
#include <string>
#include <stack>
#include <cassert>
#include <memory>
#include <random>


std::vector<int> longest_common_prefix(const std::string& str) {
	std::vector<int> result(str.size(), 0);
	result[0] = str.size();
	int r{ 0 };
	for (auto l = 1; l < str.size();) {
		for (; r + l < str.size() && str[r] == str[l + r]; ++r);
		if (r == 0) {
			++l; continue;
		}
		result[l] = r;
		int d{ 1 };
		for (; result[d] + d < r; ++d) {
			result[l + d] = result[d];
		};
		r -= d;
		l += d;
	}
	return result;
}
std::vector<bool> good_prefix(const std::string& str) {
	const auto common_prefix = longest_common_prefix(str);
	std::vector<bool> result(str.size(), true);
	for (auto i = 1; i < str.size(); ++i) {
		if (!result[i - 1]) continue;
		for (auto k = 1; k * i <= common_prefix[i]; ++k) {
			result[k * i + i - 1] = false;
		}
 	}
	return result;
}
int main() {
	std::string str; std::cin >> str;
	const auto forward = good_prefix(str);
	std::reverse(str.begin(), str.end());
	const auto backward = good_prefix(str);
	if (forward.back()) {
		std::cout << "1\n1\n";
		return 0;
	}
	if (std::distance(str.begin(), std::unique(str.begin(), str.end())) == 1) {
		std::cout << str.size() << "\n1\n";
		return 0;
	}
	int count{ 0 };
	for (auto i = 1; i < str.size(); ++i) {
		if (forward[i - 1] && backward[str.size() - i - 1]) ++count;
	}
	std::cout << "2\n" << count << '\n';
}

Measured memory_bytes: 5856
N = int(input())
A = list(map(int,input().split()))

# A[0]は0と1の間に振ったものなので、
a = 0
for i in range(N//2):
  a +=  A[2*i] - A[2*i+1]

a0 = (a + A[-1]) //2

for i in A:
  print(a0*2,end=" ")
  a0 = i - a0
  

Measured memory_bytes: 63984
//abc133
#include <iostream>
typedef long long int ll;

int mm(ll i,ll j){
    return i*j%2019;
}

int main(){
    ll l,r;
    std::cin >> l >> r;
    int min=2019;
    int temp=0;
    for(ll i=l;i<r;++i){
        for(ll j=i+1;j<=r;++j){
            temp=mm(i,j);
            if(min>temp){
                min=temp;
            }
            if(temp==0){
                break;
            }
        }
        if(temp==0){
            break;
        }
    }
    std::cout << min << std::endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

class Main
{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String s = sc.nextLine();
    String result = "";
    for (int i = 0; i < s.length(); i += 2)
    {
      result = result + s.charAt(i);
    }
    System.out.println(result);
  }
}


Measured memory_bytes: 57592
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC137
{
    class Program
    {
        static void Main(string[] args)
        {
            var kx = Console.ReadLine().Split(' ');
            var k = int.Parse(kx[0]);
            var x = int.Parse(kx[1]);
            string s = (x - (k - 1)).ToString();
            for(var i = x - (k - 1)+1; i <= x + (k - 1); i++)
            {
                s = s + " " + i.ToString();
            }
            Console.WriteLine(s);
        }
    }
}


Measured memory_bytes: 11092
#include<stdio.h>

int main()
{
	int A,B,C;
	scanf("%d %d %d",&A,&B,&C);
	if(C <= A+B){
		printf("%d\n",B+C);
	}else{
		printf("%d\n",B*2+A+1);
	}
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,k;
	cin>>k>>a>>b;
	for (int i=a;i<=b;i++)
	{
		if (i%k==0)
		{
			cout<<"OK";
			return 0;
		}
	}
	cout<<"NG";
	return 0;
} 

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

const int maxn=3e3+10;
const int mod=998244353;
const double eps=1e-6;

int n,s;
ll a[maxn],dp[maxn][maxn],ans;

int main() {
   // freopen("test.txt","r",stdin);
    cin>>n>>s;
    for(int i=1;i<=n;i++) {
        cin>>a[i];
    }
    for(int i=1;i<=n;i++) {
        for(int j=1;j<=s;j++) {
            dp[i][j]=dp[i-1][j]%mod;
            if(a[i]<j) dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%mod;
            else if(a[i]==j) dp[i][j]=(dp[i][j]+i)%mod;
        }
        ans=(ans+dp[i][s])%mod;
    }
    cout<<ans<<endl;
    return 0;
}
/*

*/


Measured memory_bytes: 70784
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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

int main()
{
  string S;
  cin >> S;
  int x,y;
  cin >> x >> y;
  int cnt = 0;
  int flag = 0;
  vector<int> X;
  vector<int> Y;
  REP(i,sz(S)){
    if(S[i]=='F'){
      cnt++;
    }else{
      if(flag==0){
        X.push_back(cnt);
        cnt=0;
        flag=1;
      }else{
        Y.push_back(cnt);
        cnt=0;
        flag=0;
      }
    }
  }
  if(flag==0){
    X.push_back(cnt);
  }else{
    Y.push_back(cnt);
  }
  x-=X[0];
  X.erase(X.begin());
  sort(ALL(X));
  sort(ALL(Y));
  reverse(ALL(X));
  reverse(ALL(Y));
  int sumx=0;
  REP(i,sz(X)){
    if(sumx<x){
      sumx+=X[i];
    }else{
      sumx-=X[i];
    }
  }
  int sumy=0;
  REP(i,sz(Y)){
    if(sumy<y){
      sumy+=Y[i];
    }else{
      sumy-=Y[i];
    }
  }
  if(sumx==x&&sumy==y){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}


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

int main() {
  int X, Y;
  cin >> X >> Y;
  
  for(int i = 0; i < X + 1; i++) {
    int leg = (X - i) * 4 + (i * 2);
    if(leg == Y) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3632
let n, m = Scanf.scanf " %d %d" @@ fun a b -> a, b
let ab_s = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> a, b
let f (y, c) (a, b) =
  if c + b >= m then ((m - c) * a + y |> Printf.printf "%d\n"; exit 0);
  y + b * a, c + b
let _ =
  Array.sort compare ab_s;
  Array.fold_left f (0, 0) ab_s

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

int dp[200010][2];
string s;

int solve(int pos, int pre){
	if(pos==SZ(s))return 0;
	int &r=dp[pos][pre];
	if(r>=0)return r;
	if(s[pos]=='D') r=1+(pre==1)+solve(pos+1,0);
	else if(s[pos]=='P') r=solve(pos+1,1);
	else{
		r=1+(pre==1)+solve(pos+1,0);
		r=max(r,solve(pos+1,1));
	}
	return r;
}

int main(){FIN;
	cin>>s;
	memset(dp,-1,sizeof(dp));
	int pos=0,pre=0;
	string ans;
	while(pos<SZ(s)){
		if(s[pos]=='D') ans.pb(s[pos]),pos++,pre=0;
		else if(s[pos]=='P')ans.pb(s[pos]),pos++,pre=1;
		else if(solve(pos,pre)==solve(pos+1,1)) ans.pb('P'),pos++,pre=1;
		else ans.pb('D'),pos++,pre=0;
	}
	cout<<ans<<"\n";
}

Measured memory_bytes: 14752
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
#define INF 0x1FFFFFFF

using namespace std;

int main(void){
	int n, m, s, c, g1, g2, b1, b2, i, j, k, ans, w[100][100];
	while(1){
		scanf("%d%d%d%d%d",&n,&m,&s,&g1,&g2);
		if(n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0)
			break;
		s--, g1--, g2--;
		
		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++) w[i][j] = INF;
			w[i][i] = 0;
		}

		for(i = 0;i < m;i++){
			scanf("%d%d%d",&b1,&b2,&c);
				w[b1 - 1][b2 - 1] = c;
		}

		for(i = 0;i < n;i++){
			for(j = 0;j < n;j++){
				for(k = 0;k < n;k++)
					w[j][k] = min(w[j][k],w[j][i] + w[i][k]);
			}
		}
		ans = INF;
		for(i = 0;i < n;i++){
			ans = min(ans,w[s][i] + w[i][g1] + w[i][g2]);
		}
		printf("%d\n",ans);

	}
	return 0;
}

Measured memory_bytes: 1064
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<vector<pair<ll,ll>>> ar(n+1);
    ll p[m];ll y[m];
    ll ans[m];
    for(int i=0;i<m;i++)
    {
         cin>>p[i]>>y[i];
        ar[p[i]].pb(mp(y[i],i));
    }
    for(int i=1;i<=n;i++)
  {  sort(ar[i].begin(),ar[i].end());
        for(int j=0;j<ar[i].size();j++)
        {
            ans[ar[i][j].second]=j+1;
        }
  }
  for(int i=0;i<m;i++)
  {
      ll af[6]={0};
      ll o=0;
      while(p[i])
      {
          af[o++]=p[i]%10;
          p[i]/=10;
      }
      reverse(af,af+6);
      for(int i=0;i<6;i++)
      cout<<af[i];
      memset(af,0,sizeof(af));
      o=0;
    while(ans[i])
      {
          af[o++]=ans[i]%10;
          ans[i]/=10;
      }
      reverse(af,af+6);
      for(int i=0;i<6;i++)
      cout<<af[i];

      cout<<"\n";
  }
   return 0;

}


Measured memory_bytes: 9344
from bisect import bisect_left,bisect_right

n = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

ans = 0
for bi in B:  
  ans += bisect_left(A,bi) * (n-bisect_right(C,bi))
  
print(ans)  

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

int N, M, T;
vector<int> A[9];

void dfs(int node, vector<bool> vis, int sum){
	if(sum == N) T++;
	else{
		vis[node] = true, sum++;
		for(int i = 0; i < A[node].size(); i++)
			if(!vis[A[node][i]]) dfs(A[node][i], vis, sum);
	}
}

int main(){
	scanf("%d%d", &N, &M);
	for(int i = 0; i < M; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		A[a].push_back(b), A[b].push_back(a);
	}
	dfs(1, {false, false, false, false, false, false, false, false, false}, 1);
	printf("%d\n", T);
	return 0;
}


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

int getGcm(int a, int b){
	int l;
	int s;
	int r;
	if(a>b) {
		l = a;
		s = b;
	} else {
		l = b;
		s = a;
	}
	r = l % s;
	while(r){
		l = s;
		s = r;
		r = l % s;
	}
	return s;
}

int main(){
	int n, x;
	int x_tmp;
	int gcm;
	scanf("%d %d\n", &n, &x);
	for(int i=0; i<n; i++) {
		scanf("%d", &x_tmp);
		if(i==0) gcm = abs(x_tmp-x);
		else gcm = getGcm(gcm, abs(x_tmp-x));
	}
	printf("%d\n", gcm);
	return 0;
}




Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;
    

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        string S = cin.next();

        int[] cnt = new int[26];
        for (int i = 0; i < N; i++)
        {
            cnt[S[i] - 'a']++;
        }

        long mod = 1000000007;

        long ans = 1;
        for (int i = 0; i < 26; i++)
        {
            ans *= cnt[i] + 1;
            ans %= mod;
        }

        ans += mod - 1;
        ans %= mod;

        Console.WriteLine(ans);
    }

}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


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

int x[1000][1000];

int main(){
    memset(x,-1,sizeof(x));
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x[0][i];
	}
	for(int i=0;i<n;i++){
		cout<<x[0][i];
		if(i!=n-1){
			cout<<' ';
		}
		else{
			cout<<endl;
		}
	}
	for(int i=1;i<n;i++){
		for(int j=0;j<i;j++){
			if(x[i-1][i]<x[i-1][j]){
				x[i][j+1]=x[i-1][j];
			}
			else{
				x[i][j]=x[i-1][j];
			}
		}
		for(int j=i+1;j<n;j++){
			x[i][j]=x[i-1][j];
		}
		for(int j=0;j<i+1;j++){
			if(x[i][j]==-1){
				x[i][j]=x[i-1][i];
			}
		}
		for(int j=0;j<n;j++){
			cout<<x[i][j];
			if(j!=n-1){
				cout<<' ';
			}
			else{
				cout<<endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 5072
#include<stdio.h>
int binarysearch(int );

int a[1000000],n;

int main(){
  int i,q,t,count=0;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&q);

  for(i=0;i<q;i++){
    scanf("%d",&t);
    if(binarysearch(t)) count++;
  }

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

  return 0;
}

int binarysearch(int k){
  int l=0;
  int m;
  int r=n;

  while(l<r){
    m=(l+r)/2;
    if(k==a[m]) return 1;
    if(k>a[m]) l=m+1;
    else if(k<a[m]) r=m;
  }
  return 0;
}



Measured memory_bytes: 2128
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
const int maxn = 3e5 + 5;

int  x[maxn], y[maxn],cntx[maxn],cnty[maxn];

int main()
{
    int n, m, k;
    cin >> n >> m >> k;
    int mx = 0, my = 0;
    for (int i = 1; i <= k; ++i)
    {
        cin >> x[i] >> y[i];

        cntx[x[i]]++;
        mx = max(mx, cntx[x[i]]);

        cnty[y[i]]++;
        my = max(my, cnty[y[i]]);
    }
    long long  t1 = 0, t2 = 0, t = 0;
    for (int i = 1; i <= n; ++i)
        if (cntx[i] == mx)
            t1++;
    for (int i = 1; i <= m; ++i)
        if (cnty[i] == my)
            t2++;
    
    for (int i = 1; i <= k; ++i)
    {
        if (cntx[x[i]] == mx && cnty[y[i]] == my)
            t++;
    }
    if (t == t1*t2)
        cout << mx + my -1<< endl;
    else
        cout << mx + my  << endl;
    return 0;
}


Measured memory_bytes: 8304
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

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

    map<char,int> mp;
    rep(j,s[0].size()) mp[s[0][j]]++;

    for(int i=0;i<n;i++){
        int m=s[i].size();
        map<char,int> tmp;
        rep(j,m) tmp[s[i][j]]++;
        for(char j='a';j<='z';j++){
            mp[j]=min(mp[j],tmp[j]);
        }
    }
    string ans="";
    for(auto e : mp){
        int m=e.second;
        rep(i,m){
            ans+=e.first;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
	int a;
	int b;
	int c;
	int e = 0;
	cin >> a >> b >> c;

	for (int i = a; i <= b; i++){
		if (c%i == 0){
			e++;
		}
	}
	cout << e << endl;
	return 0;
}

Measured memory_bytes: 3100
/*#include <iostream>
#include <string>
using namespace std;

int main(){
	 ios::sync_with_stdio(false);
	string a, b;
	int x, i = 0;
	cin >> a >> b;
	for(int i = 0;a[i];i++){
		i = a.find(b, i);
		if(i == -1)break;
		cout << i << endl;
	}
	while((x = a.find(b, i)) != -1){
		cout << x << endl;
		i = x + 1;
	}
	return 0;
}*/

#include <iostream>
#include <string>
using namespace std;
string t,p;
int main(){
	//ios::sync_with_stdio(false);
	cin>>t>>p;
	for(int i=0;t[i];i++){
		i=t.find(p, i);
		if(i==-1)break;
		cout<<i<<'\n';
	}
	return 0;
}

Measured memory_bytes: 3956
fun main(args: Array<String>) {
    agc024a()
}

fun agc024a() {
    val (a, b, c, k) = readLine()!!.split(' ').map { it.toLong() }

    val answer = (a - b) * if (k % 2 == 0L) 1 else -1

    println(answer)
}


Measured memory_bytes: 38252
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <climits>
using namespace std;

int dfs (vector<string> &s, int x, int y, int h, int w) {
    
    int adj = 1;
    int dx[4] = {0, 0, 1, -1};
    int dy[4] = {1, -1, 0, 0};

    stack<pair<int, int> > st;
    s[x][y] = '.';
    st.emplace(x, y);

    while (!st.empty()) {
        int xx = st.top().first, yy = st.top().second;
        st.pop();
        for (int i = 0; i < 4; i++) {
            int nx = xx + dx[i], ny = yy + dy[i];
            if (nx < 0 || nx >= h || ny < 0 || ny >= w) continue;
            if (s[nx][ny] == '#') {
                st.emplace(nx, ny);
                s[nx][ny] = '.';
                adj++;
            }
        }
    }

    return adj;
}

int main () {

    int H, W;
    cin >> H >> W;

    vector<string> s(H);
    for (int i = 0; i < H; i++) {
        cin >> s[i];
    }

    int min_adj = INT_MAX;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                int adj = dfs(s, i, j, H, W);
                min_adj = min(adj, min_adj);
            }
        }
    }

    if (min_adj != 1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(ll i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define ll long long

int main(void){
  int n;
  cin>>n;
  vl a(n);
  rep(i,n)cin>>a[i];
  ll sum=a[0];
  ll ans1=0;
  rep(i,n){
    if(i%2==0){
      if(sum>=0){
        ans1+=sum+1;
        sum=-1;
      }
    }else{
      if(sum<=0){
        ans1+=-sum+1;
        sum=1;
      }

    }
    if(i!=n-1){
    sum+=a[i+1];

    }
  }
  sum = a[0];
  ll ans2=0;
  rep(i,n){
    if(i%2==0){
      if(sum<=0){
        ans2+=-sum+1;
        sum=1;
      }
    }else{
      if(sum>=0){
        ans2+=sum+1;
        sum=-1;
      }
    }
    if(i!=n-1){
    sum+=a[i+1];

    }
  }
  cout<<min(ans1,ans2)<<endl;
  return 0;
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
#define rep0c(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep1c(i, n) for (int i = 1; i <= (int)(n); i++)
#define repc0(n, i) for (int i = (int)(n); i >= 0; i--)

using namespace std;
typedef long long ll;

typedef pair<int, int> BA;
int N;
priority_queue<BA, vector<BA>, greater<BA> > que;

void solve() {
  int t = 0;
  while(!que.empty()) {
    BA ba = que.top(); que.pop();
    t += ba.second;
    if(ba.first < t) {
      printf("No\n");
      return;
    }
  }
  printf("Yes\n");
  return;
}

int main() {
  scanf("%d", &N);
  rep(i, N) {
    int a, b;
    scanf("%d %d", &a, &b);
    que.push(make_pair(b, a));
  }
  solve();
  return 0;
}

Measured memory_bytes: 2420
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>

using namespace std;

struct edge {int to, cap, rev; };

vector<edge> G[110];
bool used[110];

void add_edge(int from,int to,int cap){
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size() - 1});
}

int dfs(int v,int t,int f){
	if(v==t) return f;
	used[v]=true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];
		if(!used[e.to] && e.cap >0){
			int d = dfs(e.to,t,min(f,e.cap));
			if(d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int V,E,u,v,c;

int main(){
	cin >> V >> E;
	for(int i=0;i<E;i++){
		cin >> u >> v >> c;
		add_edge(u,v,c);
	}
	int flow = 0;
	while(1){
		memset(used,0,sizeof(used));
		int f = dfs(0,V-1,9999999);
		if(f == 0){
			cout << flow << endl;
			return 0;
		}
		flow += f;
	}
}	

Measured memory_bytes: 3172
#include<stdio.h>
#include<math.h>
int main(void)
{
	int a,b,c;
	int tyo,hishi;
	tyo=0;
	hishi=0;
	while(scanf("%d,%d,%d",&a,&b,&c)!=EOF){
		if(a==b){
			hishi++;
		}
		if(c*c==a*a+b*b){
			tyo++;
		}
	}
	printf("%d\n%d\n",tyo,hishi);
	return 0;
}

Measured memory_bytes: 1024
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-10 20:47:22
*/

#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

int main()
{
    int n, m;
    cin >> n >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; i++)
        cin >> a[i] >> b[i];

    vector<int> con(n, 0);
    for (int i = 0; i < m; i++) {
        con[a[i]-1]++;
        con[b[i]-1]++;
    }

    for (int i = 0; i < n; i++)
        cout << con[i] << endl;

    return 0;
}


Measured memory_bytes: 256
def func() :
    s = input()
    for i in range(len(s)) :
        if i % 2 == 0 :
            if list(s)[i] == 'L' :
                return('No')
        else :
            if list(s)[i] == 'R' :
                return('No')
    return('Yes')
print(func())


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

int main(){
  int a,b;
  cin >> a >> b;
  int p = a + b;
  int s = a - b;
  int m = a * b;
  int ans = p;
  if(ans < s) ans = s;
  if(ans < m) ans = m;
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int j;
    char m[3][4];
    for(j=0;j<3;j++)
    scanf("%c%c%c%c",&m[j][0],&m[j][1],&m[j][2],&m[j][3]);
    printf("%c%c%c",m[0][0],m[1][1],m[2][2]);
    }


Measured memory_bytes: 128
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	public static void main(String[] args) {
			String A=sc.next();
			String B=sc.next();
			if(A.equals(B)) {
				p("EQUAL");
			}else if(A.length()>B.length()) {
				p("GREATER");
			}else if(A.length()<B.length()) {
				p("LESS");
			}else
			if(A.length()==B.length()) {
				char a,b;
				
				for(int i=0;i<A.length();i++) {
					a=A.charAt(i);
					b=B.charAt(i);
					if(a>b) {
						p("GREATER");
						break;
					}else if(a<b) {
						p("LESS");
						break;
					}
				}
			}
			
			
			
			
			
			
			
			
			
			
	}

	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 21716
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    char[][] s = new char[H + 2][W + 2];
    for (int i = 1; i <= H; i++) {
      char[] row = sc.next().toCharArray();
      for (int j = 1; j <= W; j++) {
        s[i][j] = row[j - 1];
      }
    }
    for (int i = 1; i <= H; i++) {
      for (int j = 1; j <= W; j++) {
        if (s[i][j] == '#' && !check(s, i, j)) {
          System.out.println("No");
          return;
        }
      }
    }
    System.out.println("Yes");
  }

  public static boolean check(char[][] s, int i, int j) {
    if (s[i - 1][j] == '#') {
      return true;
    }
    if (s[i][j - 1] == '#') {
      return true;
    }
    if (s[i][j + 1] == '#') {
      return true;
    }
    if (s[i + 1][j] == '#') {
      return true;
    }
    return false;
  }
}

Measured memory_bytes: 21972
def main():
	n , k = map(int , input().split())
	hd = input()
	grp=[]
	if hd[0]=='1':
		grp = [[0,0]]
	else:
		grp=[[0,0]]
	cnt =1
	for i in range(1, len(hd)):
		if hd[i]==hd[i-1]:
			cnt = cnt+1
		else:
			grp.append([cnt,i])
			cnt = 1
	grp .append([cnt , len(hd)-1])
	pre = [0 for i in range(0 , len(grp)+9)]
	pre[0]=grp[0][0]
	for i in range(1, len(grp)):
		pre[i]=pre[i-1]+grp[i][0]
	ans = 0
	for i in range(0 , len(grp)):
		if hd[grp[i][1]]=='0':
			rgt = min(i+2*k, len(grp)-1)
			ans = max(ans, pre[rgt]-pre[i])
		else:
			rgt = min(i+2*k+1, len(grp)-1)
			ans = max(ans, pre[rgt]-pre[i])
		if rgt==len(grp)-1:
			break
	print(ans)
if __name__=="__main__":
	main()

Measured memory_bytes: 88492
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

template < typename T >
void vprint(T &V){
	for(auto v : V){
    	cout << v << " ";
	}
	cout << endl;
}

const ll mod = 1e9 + 7;
const ll inf = 1e18;

bool is_num_char(char c){
    if('0'<= c && c <= '9'){
        return true;
    }else{
        return false;
    }
}

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

    // input
    ll A, B;
    cin >> A >> B;

    string s;
    cin >> s;

    FOR(i, 0, s.size()){
        char c = s[i];
        if(i==A){
            if(c!='-'){
                p_no();
                return 0;
            }
        }
        else{
            if(!is_num_char(c)){
                p_no();
                return 0;
            }
        }
    }

    p_yes();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define ul unsigned long long int
#define ld long double
#define f(t) for(ll i =0;i<t;i++)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ff first
#define ss second
#define MOD 1000000007
#define inf 4e18
#define EPS 1e-3
#define PI 3.1415926535897932385
#define display(v) f(v.size())cout << v[i]<<" "
const double h = 1e-6;
const int MAX_  = 200005;
#define all(v) v.begin(),v.end()

inline ll mul(ll a, ll b){ return (a * 1ll * b) % MOD; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += MOD; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c > MOD) c -= MOD; return c; }
ll sqr(ll x)
{
    return x*x;
}
 //////////////////////*********CODE***********/////////////////////
 //////////////////////////////////////////////////////////////////
struct graph{
    vi v;
};

void bfs(graph G[],int start,vl & d){
    queue<int> q;
    q.push(start);
    d[start] = 0;
   
    while(!q.empty()){
        int from = q.front();
        q.pop();
        for(int i=0;i<G[from].v.size();i++){
            int to = G[from].v[i];
          //  cout << from << "  " << to << "\n";
            if(d[to] == inf){
                d[to] = d[from]+1;
                q.push(to);
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,l;
    cin>>n>>l;
    vi v(n);
    int sum = 0;
    for(int i =0;i<n;i++){
        v[i] = l + i;
        sum += v[i];
    }
    int ab = INT_MAX;
    int val;
    for(int i =0;i<n;i++){
        if(abs(sum - (sum-v[i])) < ab ){
            ab = abs(sum - (sum-v[i]));
            val = v[i];
        }
    }
    cout << sum -val;
    return 0;
}
    


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

typedef long long ll;
const int INF = 1e9 + 5;
int main() {
	ios_base::sync_with_stdio(false);

	int n, k;
	cin >> n >> k;
	vector<int> h(n), dp(n, INF);
	dp[0] = 0;
	for (int i = 0; i < n; i++) cin >> h[i];

	for (int i = 0; i < n - 1; i++) {
		for (int j = i + 1; j <= i + k && j < n; j++) {
			dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
		
	}
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(a, b) for(int a = 0; a < b; a++)
#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define mp make_pair
#define f first
#define s second
#define pb push_back
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, ll> LL;
typedef vector<int> vi;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const int MAXN = 1e5 + 100;

ll nyak[MAXN][2];
int n;
vi v[MAXN];
int p[MAXN];
bool sudah[MAXN];

void dfs(int x) {
	REP(i, v[x].size()) {
		int now = v[x][i];
		if (!sudah[now]) {
			sudah[now] = 1;
			p[now] = x;
			dfs(now);
		}
	}
	return;
}

ll DP(int x, int col) {
	//cout << x << ' ' << col << ' ' << p[x] << '\n';
	ll &ret = nyak[x][col];
	if (ret != -1) return ret;
	ret = 1;
	REP(i, v[x].size()) {
		int now = v[x][i];
		if (now == p[x]) continue;
		if (col == 0) {
			ret = (ret * DP(now, 1)) % MOD;
		}
		else {
			ret = (ret * ((DP(now, 1) + DP(now, 0)) % MOD)) % MOD;
		}
	}
	return ret;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	REP(i, n - 1) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		v[a].pb(b);
		v[b].pb(a);
	}
	p[0] = -1;
	sudah[0] = 1;
	dfs(0);
	memset(nyak, -1, sizeof nyak);
	cout << (DP(0, 0) + DP(0, 1)) % MOD << '\n';
}

Measured memory_bytes: 17536
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	int n, l;
	cin >> n >> l;

	int ans = 0;
	if (l > 0)
	{
		for (int i = 0; i < n - 1; i++)
		{
			l++;
			ans += l;
		}

		cout << ans << endl;
	}
	else if(l * 2 * -1 <= n)
	{
		for (int i = 0; i < n; i++)
		{
			ans += l;
			l++;
		}

		cout << ans << endl;
	}
	else
	{
		for (int i = 0; i < n - 1; i++)
		{
			ans += l;
			l++;
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n, max=0, max2=0;
    cin >> n;
    vector<int> a(n);
    
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(a[i]>max){
            max = a[i];
        } else if(a[i]>max2){
            max2 = a[i];
        }
    }
    
    for(int i=0;i<n;i++){
        if(max==a[i]){
            cout << max2 << endl;
        } else {
            cout << max << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;
class Main 
{
  public static void main(String[] args) 
  {
    Scanner input=new Scanner(System.in);
    int a=input.nextInt();
    int b=input.nextInt();
    if(a>=1 && a<=100 && b>=1 && b<=100)
    {
      String temp=""+a+""+b;
      int c=Integer.parseInt(temp);
      Double d=Math.sqrt(c);
      int e = d.intValue();
      if(d==e)
      {
        System.out.println("Yes");
      }else
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a[3],n,ans=0;
	cin>>a[0]>>a[1]>>a[2]>>n;
	sort(a,a+3);
	for(int i=0;i<=n/a[2];i++)
	 for(int j=(n-i*a[2])/a[1];j>=0;j--)
	  if((n-i*a[2]-j*a[1])%a[0]==0)
	   ans++;
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  string t;
  cin >> s >> t;
  
  int count = 0; 
  for (int i; i< 3; i++) {
   if ( s.at(i) == t.at(i) ){
     count++;
   }
  }
 
  
  cout << count;
}


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

typedef long long LL;

int main()
{
	LL a,b,n;
	cin>>a>>b>>n;
	if(n>=b)
	{
		n-=n%b;
		n--;
	}
	cout<<n*a/b-a*(n/b)<<endl;
	return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int a[100005];
int main()
{
	string s;
	long long total=0,pos=1;
	getline(cin,s);
	for (int i=1;i<=s.size();i++)  a[i]=s[i-1]-48;
	for (int i=s.size();i>=1;i--)
	{
		total+=a[i]*pos;
		pos*=10;
		if (total>=2800||pos>2138475648)
		{
			cout<<"AGC"<<endl;
			return 0;
		}
	}	
	if (total<1200)  cout<<"ABC"<<endl;
	else cout<<"ARC"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <map>

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

using namespace std;
typedef long long ll;
const int mod = 1000000007;

int INF = 1001001001;
typedef pair<int, int> P;

int dist[100005][3];

int main() {
    int n, m;
    cin >> n >> m;

    vector<vector<int> > t(n);
    rep(i, m) {
        int u, v;
        cin >> u >> v;
        --u; --v;
        t[u].push_back(v);
    }

    int sv, tv;
    cin >> sv >> tv;
    --sv, --tv;
    rep(i,n)rep(j,3) dist[i][j] = INF;
    dist[sv][0] = 0;
    queue<P> q;
    q.push(P(sv, 0));

    while(!q.empty()) {
        int v = q.front().first;
        int l = q.front().second;
        q.pop();
        for(int u : t[v]) {
            int nl = (l+1) % 3;
            if (dist[u][nl] != INF) continue;
            dist[u][nl] = dist[v][l] + 1;
            q.push(P(u, nl));
        }
    }

    int ans = dist[tv][0];
    if (ans == INF) ans = -1;
    else ans /= 3;
    cout << ans << endl;
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0; i < n; ++i) cin >> a[i];
	int ans = 0;
	while(true){
		bool odd = false;
		for(int i = 0; i < n; ++i){
			if(a[i]%2 != 0) odd = true;
		}
		if(odd) break;
		for(int i = 0; i < n; ++i) a[i] /= 2;
	++ans;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
list($n) = ints();
$l = ints();
sort($l);
$cnt = 0;
for ($i = 0; $i < $n - 2; ++$i) {
    for ($j = $i + 1; $j < $n - 1; ++$j) {
        for ($k = $j + 1; $k < $n; ++$k) {
            if ($l[$i] === $l[$j] || $l[$j] === $l[$k] || $l[$i] === $l[$k]) continue;
            if ($l[$i] + $l[$j] <= $l[$k]) continue;
            ++$cnt;
        }
    }
}
echo $cnt;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 16180
#include <stdio.h>
int main ()
{
    int a, b, c, x, i, j, k, cnt=0;
    scanf("%d%d%d%d", &a, &b, &c, &x);
    for (i=0; i <= a && 500*i<=x; i++)
    {
        for (j=0; j <= b && 100*j+500*i<=x; j++)
        {
            for (k=0; k <= c && 50*k+100*j+500*i<=x; k++)
            {
                if (500*i+100*j+50*k==x)
                {
                    cnt++;
                }
            }
        }
    }
    printf("%d\n", cnt);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <stack>
#include <string>
#include <cstring>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <climits>

using namespace std;

const int N = 3e5 + 5000;
long long n, m, T, a[N];
int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	long long ans = n / 500 * 1000;
	ans += n % 500 / 5 * 5;
	cout << ans;
	return 0;
}



Measured memory_bytes: 256
(setq *s* (concatenate 'list (read-line)))

(defun ans (s parity)
  (cond
    ((equal (car s) nil)
     "Yes")
    ((< parity 0)
     (if (not (equal (car s) #\R)) (ans (cdr s) (* -1 parity)) "No"))
    ((> parity 0)
     (if (not (equal (car s) #\L)) (ans (cdr s) (* -1 parity)) "No"))))

(format t "~a~%" (ans *s* 1))

Measured memory_bytes: 5224