akhauriyash/Code-Regression huggingface dataset:
/*Priyansh Agarwal*/
#include<bits/stdc++.h>
#include<algorithm>
#include<unordered_map>
#include<vector>
#include<unordered_set>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define MOD 1000000007
#define MOD1 998244353
#define nline "\n"
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cout << #x << " " << x <<endl;
typedef long long ll;
typedef unsigned long long ull;
typedef priority_queue<int, vector<int>, function<bool(int, int)>> pq_func;
/*---------------------------------------------------------------------------------------------------------------------------*/
int gcd(int a, int b) {if (b > a) {return gcd(b, a);} if (b == 0) {return a;} return gcd(b, a % b);}
ll expo(ll a, ll b, ll mod) {ll res = 1; while (b > 0) {if (b & 1)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
vector<int> sieve(int n) {int*arr = new int[n + 1](); vector<int> vect; for (int i = 2; i <= n; i++)if (arr[i] == 0) {vect.push_back(i); for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return vect;}
void extendgcd(ll a, ll b, ll*v) {if (b == 0) {v[0] = 1; v[1] = 0; v[2] = a; return ;} extendgcd(b, a % b, v); ll x = v[1]; v[1] = v[0] - v[1] * (a / b); v[0] = x; return;} //pass an arry of size 3
ll mminv(ll a, ll b) {ll arr[3]; extendgcd(a, b, arr); return arr[0];} //for non prime b
ll mminvprime(ll a, ll b) {return expo(a, b - 2, b);}
bool revsort(ll a, ll b) {return a > b;}
void swap(int &x, int &y) {int temp = x; x = y; y = temp;}
void google(int t) {cout << "Case #" << t << ": ";}
/*--------------------------------------------------------------------------------------------------------------------------*/
int main()
{
	fastio();
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
	freopen("Error.txt", "w", stderr);
#endif
	int t;
	cin >> t;
	int a, b;
	cin >> a >> b;
	if ((b - b % t) < a)
		cout << "NG" << endl;
	else
		cout << "OK" << endl;
	return 0;
}

Measured memory_bytes: 3656
from collections import Counter
N = int(input())
A = [int(s) for s in input().split()]
Q = int(input())

d = Counter(A)
total = sum(A)

for _ in range(Q):
    b, c = [int(s) for s in input().split()]
    if d[b]:
        total += (c - b) * d[b]
        d[c] = d[b] + (d[c] if d[c] else 0)
        d[b] = 0
    print(total)



Measured memory_bytes: 21472
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  cin>>N;
  long long w=0;
  long long h=0;
  long long n=0;
  for(long long i=1;i<=3500;i++){
    for(long long j=1;j<=3500;j++){
   if((4*i*j-N*i-N*j)> 0 && (N*i*j) % (4*i*j-N*i-N*j)==0 && (N*i*j) / (4*i*j-N*i-N*j)>=1  ){
     w=(N*i*j) / (4*i*j-N*i-N*j);
     h=i;
    n=j; 
   }
   
    
    
    
    }
  }
  cout <<h<<" "<<n<<" "<<w<<endl;
 }


Measured memory_bytes: 3640
fun main(args:Array<String>){
  var s = readLine()!!.toInt()
  var a = s/100
  var b = s%100
  if(b<13 && 0<b){
    if(a<13 && 0<a){
      println("AMBIGUOUS")
    }
    else{
      println("YYMM")
    }
  }
  else{
    if(a<13 && 0<a ){
      println("MMYY")
    }
    else{
      println("NA")
    }
  }
}

Measured memory_bytes: 31748
//ヘッダー
#include<bits/stdc++.h>
using namespace std;

//型定義
typedef long long ll;

//定数
const int INF=1e+9;
const int MOD=1e+9+7;

//REPマクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REP2(i,a,b) for(ll i=a;i<(ll)(b);i++)
#define REPD2(i,a,b) for(ll i=a;i>(ll)(b);i--)

// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

//vectorの扱い
#define ALL(x) (x).begin(),(x).end() //sortなどの引数省略
#define SIZE(x) ((ll)(x).size()) //size
#define MAX(x) *max_element(ALL(x)) //最大値
#define MIN(x) *min_element(ALL(x)) //最小値

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    REP(i,N) cin>>A[i];
    sort(ALL(A),greater<ll>());
    ll ans=0;

    priority_queue<ll> que;
    que.push(A[0]);

    ans=0;
    REP2(i,1,N){
        ans+=que.top();
        que.pop();
        que.push(A[i]);
        que.push(A[i]);
    }

    cout<<ans<<endl;
}

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

double expect(int x){
    return (1+x)/2;
}

//累積和が使えそう
int main(){
    int n, k;
    cin >> n >> k;
    vector<int> p(n);
    rep(i,n) cin >> p[i];

    //累積和
    vector<double> sum(n+1);
    sum[0]=0;
    for(int i=0; i<n; i++){
        if(p[i]%2==0){
            sum[i+1] = sum[i] +p[i]/2 +0.5;
        }
        else if(p[i]%2==1){
            sum[i+1] = sum[i] +p[i]/2 + 1;
        }
    }
    double ans=0;
    for(int i=0; i<n-k+1; i++){
        double temp=sum[i+k]-sum[i];
        ans = max(ans,temp);
    }

    cout << setprecision(10) << ans << endl;

}

Measured memory_bytes: 5616
#include<stdio.h>
int main()
{
    int n;
    scanf ("%d",&n);
    long long int sum=0;
    for (int i=1;i<=n;i++)
    {
        if (i%3==0 )
        {
        }
        else if (i%5==0 )
        {            
        }
        else if (i%3==0 && i%5==0)
        {
            
        }
        else
        {
            sum=sum+i;
        }
    }
    printf ("%lld\n",sum);

}


Measured memory_bytes: 1728
#!/usr/bin/env python3
from itertools import combinations
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, K: int, x: "List[int]", y: "List[int]"):
    pts = sorted(zip(x, y))
    ys = sorted(y)
    ans = float("inf")
    for y1, y2 in combinations(ys, 2):
        xs = [x for x, y in pts if y1 <= y <= y2]
        if len(xs) >= K:
            ans = min(
                ans,
                (y2 - y1) * min(x2 - x1 for x1, x2 in zip(xs, xs[K - 1:]))
            )
    print(ans)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    x = [int()] * (N)  # type: "List[int]"
    y = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        x[i] = int(next(tokens))
        y[i] = int(next(tokens))
    solve(N, K, x, y)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include<cmath>
 
using namespace std;
 
double EPS = 1e-10;
double pi = 3.1415926535;
 
double calc(int x) {
  return sin((double)x*pi/180.0);
}
  
 
int main(void){

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

    double s1 = 0, s2 = 0, angle, c = 360;
    
    for( int i = 0 ; i < n - 1 ; i++ ){
      cin >> angle;
      c -= angle;
      s1 += calc(angle);
    }
    s1 += calc(c);

    cin >> m;
    c = 360;

    for( int j = 0 ; j < m - 1 ; j++ ){
      cin >> angle;
      c -= angle;
      s2 += calc(angle);
    }
    s2 += calc(c);

    if( s1 > s2 + EPS ) cout << 1 << endl;
    else if( s1 + EPS < s2 ) cout << 2 << endl;
    else cout << 0 << endl;
  }
 
  return 0;
}

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

using namespace std;

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

using ll = long long;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
	int a, b;
	cin >> a >> b;
	if (a >= 13) cout << b << endl;
	else if (a <= 5) cout << 0 << endl;
	else cout << b / 2 << endl;
	
    return 0;
}


Measured memory_bytes: 3616
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.numeric;
import std.stdio;
import std.string;

void main()
{
    long[] s = readln().chomp().split(" ").map!(to!(long)).array;
    long a = s[0];
    long b = s[1];
    if (a + b == 15)
    {
        writeln("+");
        return;
    }
    if (a * b == 15)
    {
        writeln("*");
        return;
    }
    writeln("x");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string n; cin >> n;
    for(int i=0; i < 3; i++){
    if(n[i] == '1') cout << "9";
    else if(n[i] == '9') cout << "1";
    else cout << n[i];
    }
    cout << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    string s;
    cin >> s;
    if( s == "Sunny"){
       cout << "Cloudy" ;
    }
    if( s == "Cloudy"){
       cout << "Rainy" ;
    }
    if( s == "Rainy"){
       cout << "Sunny" ;
    }
}

Measured memory_bytes: 256
s = list(input())
count = 0
s_1 = s[0]
for i in range(3):
    if s_1 == s[i+1]:
        del(s[i+1])
        break

tmp = s_1
del(s[0])
if len(s) == 3:
    print('No')

if len(s) == 2:
    if s[0] in tmp and s[1] in tmp:
        print('No')
    elif s[0] == s[1]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fo(a,b) for(int a=0;a<b;a++)
#define Sort(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define fi first
#define se second
 int wari(int a,int b) {
   if(a%b==0)
     return a/b;
   else
     return a/b+1;
 }
 int keta(int a){
  double b=a;
  b=log10(b);
  int c=b;
  return c+1;
 }
 int souwa(int a){
  return a*(a+1)/2;
 }
 int lcm(int a,int b){
  int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return d*e/f;
    }
  int gcm(int a,int b){
      int d=a,e=b,f;
  if(a<b)
    swap(a,b);
  int c,m=1;
  while(m){
    c=a%b;
    if(c==0){
       f=b;
      m--;
    }
    else{
      a=b;
      b=c;
 }
  }
  return f;
  }
 bool prime(int a){
   if(a<2)
     return false;
   else if(a==2)
     return true;
   else if(a%2==0)
     return false;
   double b=sqrt(a);
    for(int i=3;i<=b;i+=2){
      if(a%i==0){
        return false;
      }
    }
   return true;
 }
signed main(){
  int a;
  cin>>a;
  string b;
  cin>>b;
  if(a>=3200)
    cout<<b<<endl;
  else
    cout<<"red"<<endl;
}

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

vector<ll> to[100010];

int main(){
    ll n,ta,ao;cin>>n>>ta>>ao;
    ta--;ao--;
    rep(i,0,n-1){
        ll a,b;cin>>a>>b;
        a--;b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    vector<pair<ll,ll> > dis(n);//a,t
    rep(i,0,n)dis[i]=make_pair(-1,-1);
    queue<ll> q;
    q.push(ta);
    dis[ta].second=0;
    while(!q.empty()){
        ll now=q.front();
        q.pop();
        for(auto nx:to[now]){
            if(dis[nx].second!=-1)continue;
            dis[nx].second=dis[now].second+1;
            q.push(nx);
        }
    }
    q.push(ao);
    dis[ao].first=0;
    while(!q.empty()){
        ll now=q.front();
        q.pop();
        for(auto nx:to[now]){
            if(dis[nx].first!=-1)continue;
            dis[nx].first=dis[now].first+1;
            q.push(nx);
        }
    }
    sort(dis.begin(),dis.end(),greater<>());
    int des;
    rep(i,0,n){
        if(dis[i].first>dis[i].second){
            des=i;
            break;
        }
    }
    cout<<dis[des].first-1<<endl;
}

    









Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;

int main(){
  ll n;
  cin >> n;
  for(int i = 0;i < 1000;i++){
    if(i * 1000 >= n){
      cout << i*1000 - n << endl;
      break;
    }
  }
}


Measured memory_bytes: 3624
import java.util.*;


public class Main {
    public static void main(String[] args) {

        String ans;

        Scanner scanner = new Scanner(System.in);
        int A = scanner.nextInt();
        int B = scanner.nextInt();

        if (A*B%2 == 0){
            ans = "No";
        } else { ans = "Yes";}

        System.out.println(ans);

    }
}


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

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

const double EPS = 1e-10;

int H, W;

bool inside(int a, int b) {
	return 0 <= a && a < H && 0 <= b && b < W;
}



int main() {
	cin >> H >> W;
	vector<string> v(H);
	rep(i, H) cin >> v[i];
	// map<pair<int,int>,int> ma;
	vector<pair<double, int>> w;
	rep(i, H - 1) {
		rep(j, W - 1) {
			if(v[i].substr(j, 2) == "#." && v[i + 1].substr(j, 2) == "..") {
				double ang = 1.0 * (H - 1 - i) / (j + 1);
				w.push_back(make_pair(ang, 1));
			}
			if(v[i].substr(j, 2) == ".." && v[i + 1].substr(j, 2) == ".#") {
				double ang = 1.0 * (H - 1 - i) / (j + 1) - EPS;
				w.push_back(make_pair(ang, -1));
			}
			if(v[i].substr(j, 2) == "##" && v[i + 1].substr(j, 2) == "#.") {
				double ang = 1.0 * (H - 1 - i) / (j + 1) - EPS;
				w.push_back(make_pair(ang, -1));
			}
			if(v[i].substr(j, 2) == ".#" && v[i + 1].substr(j, 2) == "##") {
				double ang = 1.0 * (H - 1 - i) / (j + 1);
				w.push_back(make_pair(ang, +1));
			}
		}
	}
	rep(i, H - 1) {
		if(v[i][W - 1] == '#' && (i == H - 1 || v[i + 1][W - 1] == '.')) {
			double ang = 1.0 * (H - 1 - i) / (W);
			w.push_back(make_pair(ang, 1));
		}
	}
	rep(i, W) {
		if(i && v[0][i] == '#' && v[0][i - 1] == '.') {
			double ang = 1.0 * (H) / (i) - EPS;
			w.push_back(make_pair(ang, -1));
		}
		if(v[H - 1][i] == '#' && (i == W - 1 || v[H - 1][i + 1] == '.')) {
			double ang = 1.0 * (0) / (i + 1);
			w.push_back(make_pair(ang, 1));
		}
	}
	int ans = 1;
	int tmp = 1;
	sort(w.begin(), w.end());
	rep(i, w.size()) {
		tmp += w[i].second;
		ans = max(ans, tmp);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5684
N, Z, W = map(int, input().split())
A = list(map(int, input().split()))
dp = [[-1] * (N + 1) for _ in range(N + 1)]

for x in range(N, -1, -1):
    for y in range(N, -1, -1):
        if x == y:
            continue
        X = Z if x == 0 else A[x - 1]
        Y = W if y == 0 else A[y - 1]
        if x == N or y == N:
            rst = abs(X - Y)
        elif x - y == 1:
            rst = 10 ** 10
            for j in range(N, x, -1):
                rst = min(rst, dp[x][j])
        elif x - y > 1:
            rst = dp[x][y + 1]
        elif y - x == 1:
            rst = 0
            for i in range(N, y, -1):
                rst = max(rst, dp[i][y])
        elif y - x > 1:
            rst = dp[x + 1][y]
        else:
            raise Exception
        dp[x][y] = rst

ans = 0
for i in range(N):
    ans = max(ans, dp[i + 1][0])
print(ans)


Measured memory_bytes: 78300
#include <bits/stdc++.h>
#define int long long

using namespace std; 

const int maxn = 1e6; 
int n, m, cnt, p[maxn + 5], siz[maxn + 5], vis[maxn + 5], bel[maxn + 5];  
long long k, c[maxn + 5], ans[maxn + 5], na[maxn + 5], a[maxn + 5], x[maxn + 5], sta[maxn + 5]; 
int pos[maxn + 5]; 

vector <long long> v[maxn + 5]; 

signed main() {
    scanf("%lld", &n); 
    for (int i = 1; i <= n; i++) {
        scanf("%lld", &x[i]); 
    }
    for (int i = 1; i <= n; i++) {
        a[i] = x[i] - x[i - 1]; 
    }
    scanf("%lld %lld", &m, &k); 
    for (int i = 1; i <= n; i++) {
        p[i] = i; 
    }
    for (int i = 1; i <= m; i++) {
        int t; 
        scanf("%lld", &t); 
        swap(p[t], p[t + 1]); 
    }
    for (int i = 1; i <= n; i++) {
        if (vis[i]) continue ; 
        int x = i; 
        int top = 0; 
        while (!vis[x]) {
            vis[x] = 1; 
            sta[++top] = x; 
            x = p[x]; 
        }
        for (int j = 1; j <= top; j++) {
            na[sta[j]] = a[sta[(j + k - 1) % top + 1]]; 
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans += na[i];
        printf("%lld.0\n", ans);  
    }
    // for (int i = 1; i <= n; i++) printf("%.9lf\n", (double)x[i]); 
    return 0; 
}

Measured memory_bytes: 46464
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        // int n = Integer.parseInt(bf.readLine());
        StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        int n = Integer.parseInt(st.nextToken());
        int k = Integer.parseInt(st.nextToken());

        st = new StringTokenizer(bf.readLine());
        int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());

        int invcount = 0;
        for(int i=0; i<n; i++)  {
          for(int j=0; j<n-1; j++) {
            if(a[j] > a[j+1]) {
              int temp = a[j];
              a[j] = a[j+1];
              a[j+1] = temp;
              invcount++;
            }
          }
        }
        int val = n*n;
        int count = 1;
        for(int i=1; i<n; i++) {
          if(a[i] == a[i-1]) count++;
          else {
            val -= count*count;
            count=1;
          }
        }
        val -= count*count;
        val /= 2;
        int mod = 1000000007;
        long ans = 1L*k*invcount + (1L*k*(k-1)/2 % mod)* val;
        ans %= mod;
        out.println(ans);
        out.close(); System.exit(0);
    }
}


Measured memory_bytes: 23252
#include <stdio.h>
#define N 100

int main(){

  int a,i,v,j,k,count;
  int A[N];

  scanf("%d",&a);

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

  for( i = 1 ; i < a ; i++ ){
    v = A[i];
    j = i - 1;
    while( j >= 0 && A[j] > v ){
      A[j+1] = A[j];
      j--;
      count++;
    }
    A[j+1] = v;
  }
  
  for(i=0;i<a-1;i++) printf("%d ",A[i]);
  printf("%d\n",A[a-1]);
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 600
#a=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
#A=['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','R','V','W','X','Y','Z']

import sys
import numpy as np

n=int(sys.stdin.readline())
s=list([sorted(list(sys.stdin.readline().strip())) for _ in range(n)])
s.sort()

pre=''
cnt=0
ans=0
for i in range(n):
    now=s[i]
    if pre==now:
        cnt+=1
    else:
        pre=now
        ans+=(cnt+1)*cnt//2
        cnt=0
ans+=(cnt+1)*cnt//2
print(ans)


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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#define all(x) (x).begin(),(x).end()

void solve(){

}
int main(){
    int X,Y,N,M;
    cin >> N >> M >> X >> Y;
    vector<int> x(N),y(M);
    for (int i = 0; i < N; i++){
        cin >> x[i];
    }
    for (int i = 0; i < M; i++){
        cin >> y[i];
    }
    bool ok = false;
    int maxX = *max_element(all(x));
    int minY = *min_element(all(y));
    for (int i = X+1; i <= Y; i++){
        if (maxX < i && i <= minY){
            ok = true;
        }
    }
    if (ok){
        cout << "No War" << endl;
    } else {
        cout << "War" << endl;
    }



    return 0;
}


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

int main(){
    int w, h, n; cin >> w >> h >> n;
    int x[100001] = {}, y[100001] = {};
    for(int i = 0; i < n; i++){
        int u, v; cin >> u >> v;
        x[u] = max(x[u], v);
        y[v] = max(y[v], u);
    }
    for(int i = w-2; i >= 0; i--){
        x[i] = max(x[i], x[i+1]);
    }
    for(int i = h-2; i >= 0; i--){
        y[i] = max(y[i], y[i+1]);
    }
    int ans = w-1;
    for(int i = 0; i < w; i++){
        ans = min(ans, i + x[i+1]);
    }
    for(int i = 0; i < w; i++){
        ans = min(ans, i + y[i+1]);
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3888
n = int(input())
A = list(map(int, input().split()))

A = [i for i in A if i%2==0]
if len(A) != n:
    print(0)
    exit()
cnt = 0
while len(A) == n:
    A = [i//2 for i in A if i%2==0]
    cnt += 1
print(cnt-1)

Measured memory_bytes: 9024
a= int(input())
x =[int(z) for y, z in enumerate(input().split()) if y < a and z.isdigit()]
print(*x)
for i in range(1,a):
    key = x[i]
    j = i-1
    while j >= 0 and x[j] > key:
        x[j+1] = x[j]
        j -= 1
    x[j+1] = key
    print(*x)


Measured memory_bytes: 5980
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main() {
	int m, f, r;
	for (;;) {
		scanf("%d %d %d", &m, &f, &r);
		if (m == -1 && f == -1 && r == -1) break;

		if (m == -1 || f == -1) {
			printf("F\n");
			continue;
		}
		if (m + f >= 80)printf("A\n");
		else if (m + f >= 65)printf("B\n");
		else if (m + f >= 50)printf("C\n");
		else if (m + f >= 30) {
			if (r >= 50)printf("C\n");
			else printf("D\n");
		}
		else printf("F\n");
	}


	return 0;
}

Measured memory_bytes: 584
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<long long> A(n);
    long long total = 0;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    for (auto x : A) {
        total += x;
    }

    long long presum = 0;
    long long res = total;
    for (int i = 0; i < n - 1; ++i) {
        presum += A[i];
        res = min(res, abs(presum * 2 - total));
    }
    cout << res << '\n';
    
    return 0;
}

Measured memory_bytes: 1792
import java.util.*;

class Main{
  public static void main(String [] args){
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    for(int i=0;i<n;i++){
      a[i] = -Integer.parseInt(sc.next());
    }
    Arrays.sort(a);
    
    List<Integer> list = new ArrayList<>();
    long sum = 0;
    for(int i=0;i<n;i++){
      if(i==0){
        list.add(-a[i]);
      }else{
        sum+=list.get(i-1);
        list.add(-a[i]);
        list.add(-a[i]);
      }
    }
    System.out.println(sum);
  }
}

Measured memory_bytes: 65348
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    string s; cin>>s;
    int ans=sz(s); 
    for (int i=ans-1,t=0;i>=0;i--){
        if (s[i]=='T') t++;
        else {
            if (t>0) t--,ans -= 2;
        }
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

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



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

using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
#include <string>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
#include <climits>
#include <bitset>
#include <array>
#include <deque>
#include <queue>
#include <map>
#include <set>
#include <stack>
#define all(x) (x).begin(),(x).end()

const int MOD = 1e9 + 7;

void solve(){

}
int main(){
    string s;
    cin >> s;

    stack<char> st;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == 'S') {
            st.push(s[i]);
        } else if (s[i] == 'T' &&  st.size() == 0) {
            st.push(s[i]);
        } else if (s[i] == 'T' && st.top() == 'T') {
            st.push(s[i]);
        } else if (s[i] == 'T' && st.top() == 'S') {
            st.pop();
        }
    }

    cout << st.size() << endl;





    return 0;
}


Measured memory_bytes: 832
#include<bits/stdc++.h>
using namespace std;
char a[120000];
int main() {
	scanf("%s",a+1);
	if(a[1]!='A') {puts("WA");return 0;}
	if(a[2]<'a') {puts("WA");return 0;}
	bool flag=false;
	for(int i=3;i<=strlen(a+1)-1;i++) {
		if(a[i]=='C'&&flag==false) {flag=true;}
		else if(a[i]!='C'&&(a[i]>='A'&&a[i]<='Z')) {puts("WA");return 0;}
		else if(flag==true&&(a[i]>='A'&&a[i]<='Z')) {puts("WA");return 0;}
	}
	if(a[strlen(a+1)]>='A'&&a[strlen(a+1)]<='Z') {puts("WA");return 0;}
	if(!flag) {puts("WA");return 0;}
	puts("AC");
	return 0;
		
	
	
}

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

int main()
{
  int A,B,C,MAX,box=0;
  scanf("%d%d%d",&A,&B,&C);
  MAX=A*C;
  
  if(B>MAX){
    box=C;
  }else{
    for(int i=A;i<=B;i+=A){
      box++;
    }
  }
  
  printf("%d\n",box);
  
  return 0;
}

Measured memory_bytes: 256
import java.io.*;

class Main{
  public static void main(String[] args) throws IOException{
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     String str1 = br.readLine();
     String[] str2 = str1.split(" ");
     int a = Integer.parseInt(str2[0]);
     int b = Integer.parseInt(str2[1]);
     int c = Integer.parseInt(str2[2]);
     int t;

     if (a > b){
      t = a;
      a = b;
      b = t;
     }
     if (b > c){
      t = b;
      b = c;
      c = t;
     }
     if (a > b){
       t = a;
       a = b;
       b = t;
     }
     System.out.println(a + " " + b + " " + c);
  }
}

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

using namespace std;

const int maxn = 1e5 + 10;
int dp[maxn], in[maxn], n, m;
vector<int> adj[maxn];

void dfs(int u = 1)
{
    if (dp[u] != -1)
        return;
    dp[u] = 0;
    for (int v : adj[u])
        dfs(v), dp[u] = max(dp[u], dp[v] + 1);
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;

    memset(dp, -1, sizeof dp);
    for (int i = 0, u, v; i < m; i++)
        cin >> u >> v, adj[u].push_back(v), ++in[v];
    for (int i = 1; i <= n; i++)
        if (in[i] == 0)
            dfs(i);

    cout << max(0, *max_element(dp, dp + n + 1));

    return 0;
}


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

int main(){
  const int n = 26;
  char abc[n];

  for(int i = 0; i < n; i++){
    abc[i] = 'A' + i;
  }

  string s;
  int count = 0;
  int t = 0;
  cin >> s;

  for(int j = 0; j < s.size(); j++){
    if(abc[t] == 'Z'){
      t = -1;
      count++;
    } 

    for(t += 1; t < n; t++){
      if(s[j] == abc[t]) break;

      if(abc[t] == 'Z'){
        t = -1;
        count++;
      }

    }
  }
  cout << count << endl;


  return 0;
}

Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n; cin >> n;
    typedef pair<int, int> P;
    vector<P> a(n);
    rep(i,n) cin >> a[i].first, a[i].second = i+1;
    sort(a.begin(), a.end());
    rep(i,n) {
        cout << a[i].second << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1664
/* Author : bhavye9499 - Bhavye Anand Gupta */

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

typedef long long ll;
typedef long double ld;

#define endl "\n"
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pii pair<ll,ll>
#define showArr(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i] << " "; cout << endl;}
#define showPair(A,a,n) {for(int i=a; i<a+n; i++) cout << A[i].fi << " " << A[i].se << endl;}

const ll MOD = 1e9 + 7;

ll n;
double A[3010], dp[3010][3010];

double fun(ll i, ll j);

int main() {
    ios::sync_with_stdio(false);
    for(int i = 0; i < 3010; i++) {
    	for(int j = 0; j < 3010; j++) {
    		dp[i][j] = -1;
    	}
    }

    cin >> n;
    for(int i = 0; i < n; i++) {
    	cin >> A[i];
    }
    
    double ans = fun(0, 0);

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

double fun(ll i, ll j) {
	if(dp[i][j] != -1)
		return dp[i][j];
	if(i + j == n && i > n / 2)
		return dp[i][j] = 1;
	if(i + j == n && i <= n / 2)
		return dp[i][j] = 0;
	return dp[i][j] = A[i + j] * fun(i + 1, j) + (1 - A[i + j]) * fun(i, j + 1);
}

Measured memory_bytes: 71296
//0557 A First Grader
#include <iostream>
using namespace std;
const int MAX_N = 100;
int n, a[MAX_N];
long long int dp[MAX_N + 1][21];
int main(){
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a[i];
	}
	dp[0][a[0]] = 1;
	for (int i = 1; i < n - 1; i++){
		for (int j = 0; j <= 20; j++){
			if (j + a[i] <= 20)
				dp[i][j] += dp[i - 1][j + a[i]];
			if (j - a[i] >= 0)
				dp[i][j] += dp[i - 1][j - a[i]];
		}
	}

	cout << dp[n - 2][a[n - 1]] << endl;
}

Measured memory_bytes: 1172
n=gets.chomp.to_i
t=[]
for i in 0..n-1
  s,p=gets.chomp.split(" ")
  t[i]=[s,p.to_i,i+1]
end
t=t.sort{|a,b|
2*(a[0]<=>b[0])+(b[1]<=>a[1])
}

for i in 0..n-1
  puts t[i][2]
end


Measured memory_bytes: 1788
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func solve(x, y int) int {
	if x*y > 0 {
		if x <= y {
			return y - x
		} else {
			return x - y + 2
		}
	} else if x*y == 0 {
		if x <= y {
			return y - x
		} else {
			return x - y + 1
		}
	} else {
		return abs(x+y) + 1
	}
}

func main() {
	x, _ := strconv.Atoi(input())
	y, _ := strconv.Atoi(input())
	fmt.Println(solve(x, y))
}


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

#define LL long long int
#define LD long double
#define inp_s ios::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0)
#define mod 1000000007

int main(){
      LL n, a[100010], m;
      cin >> n >> m;
      for(int i=1 ; i<=n ; i++){
            cin >> a[i];
      }
      map<LL, LL> M;
      M[0LL]++;
      LL ans = 0LL, b = 0;
      for(int i=1 ; i<=n ; i++){
            b += a[i];
            b %= m;
            ans += M[b];
            M[b]++;
      }
      cout <<  ans << '\n';
      return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, less<>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//998244353;
const int base = 2187;
const double eps = 1e-8;
const int N = 100'000;
const int LOGN = 18;

int n, m, k;

void solve(int test)
{
  int l, r;
  cin >> l >> r;
  m = 2019;
  int ans = m - 1;
  r = min(r, l + m + m + m);
  for (int i = l; i <= r; ++i) {
    for (int j = i + 1; j <= r; ++j) {
      ans = min(ans, (i % m) * (j % m) % m);
    }
  }
  cout << ans << '\n';
}

void precalc()
{
}

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i)
    solve(i);
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;
  cin>>N;
  vector<long> A(N);
  for(int i=0;i<N;i++)cin>>A[i];
  long dp[1<<17][2];
  dp[0][0]=0;
  dp[0][1]=-(1L<<60);
  for(int i=0;i<N;i++){
    dp[i+1][0]=max(dp[i][0]+A[i],dp[i][1]-A[i]);
    dp[i+1][1]=max(dp[i][0]-A[i],dp[i][1]+A[i]);
  }
  cout<<dp[N][0]<<endl;
  return 0;
}


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

int main (){
  string w;
  cin >> w;
  
  sort(w.begin(), w.end());
  
  string ans = "Yes";
  
  int i = 0;
  
  if(w.size() %2 != 0){
    ans = "No";
  }
  
  else{
  while(i < w.size() - 1){
    if(w.at(i) != w.at(i+1)){
      ans = "No";
      break;
    }
    i = i + 2;
  }
  }

  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int n,a,b[200005];
long long ans=0;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&a);
 		b[i]=a-i;
	}
	sort(b,b+n);
	for(int i=0;i<n;i++) ans+=abs(b[i]-b[(n-1)/2]);
  	printf("%lld\n",ans);
  	return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pf printf
#define sc scanf
#define sf(num) scanf("%d",&num)
#define sff(num1,num2) scanf("%d %d",&num1,&num2)
#define sfff(num1,num2,num3) scanf("%d %d %d",&num1,&num2,&num3);
#define sl(num) scanf("%lld",&num)
#define sll(num1,num2) scanf("%lld %lld",&num1,&num2)
#define slll(num1,num2,num3) scanf("%lld %lld %lld",&num1,&num2,&num3);
#define rep(i,n) for(i=1;i<=n;i++)
#define rep0(i,n) for(i=0;i<n;i++)
#define reps(i,a,n) for(i=a;i<=n;i++)
#define pb push_back
#define mpp make_pair
#define MOD 1000000007
#define fi first
#define se second
#define N 100005
#define mem(ara,n) memset(ara,n,sizeof(ara))
#define memb(ara) memset(ara,false,sizeof(ara))
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define pi pair<int,int>
#define pii pair<pair<int,int>,pair<int,int> >
#define db(x) cout<<#x<<" :: "<<x<<"\n";
#define dbb(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define fr freopen("input.txt","r",stdin);
#define fw freopen("output.txt","w",stdout);
#define TIME cerr<<"Time : "<<(double)clock()/(double)CLOCKS_PER_SEC<<"s\n";
typedef long long int ll;
using namespace std;
int main()
{
    int n,l;
    sff(n,l);
    vector<int>vec;
    int i,j,sum=0;
    rep(i,n)
    {
        vec.pb(i+l-1);
        sum+=(i+l-1);
    }
    int diff=INT_MAX,ans;
    rep0(i,n)
    {
        int temp=0;
        rep0(j,n)
        {
            if(j==i)
            {
                //temp-=vec[j];
                continue;
            }
            temp+=vec[j];
        }
        if(abs(sum-temp)<diff){
            ans=temp;
            diff=abs(sum-temp);
        }
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int a[8],x,i,c,d,e,f,g;
	for(i=0;~scanf("%d",a+i++);){
		if(i==8){
			for(c=d=x=i=0;i<4;i++){
				e=a[i];f=a[i+4];
				if(e==f)c++;
				else{
					if(x&1<<e)d++;
					x|=1<<e;
					if(x&1<<f)d++;
					x|=1<<f;
				}
			}
			i=!printf("%d %d\n",c,d);
		}
	}
	return 0;
}

Measured memory_bytes: 0
val MOD = 1000000007L

fun main(args : Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toLong() }

    if (Math.abs(n-m) >= 2L) {
        println(0)
        return
    }

    if (n == m) {
        val mp = modPerm(n, n, MOD)
        println((2 * mp % MOD) * mp % MOD)
    } else {
        println(modPerm(n, n, MOD) * modPerm(m, m, MOD) % MOD)
    }
}

fun modPerm(n: Long, k: Long, m: Long): Long {
    require(n > 0 && k >= 0)
    return (n - k + 1 .. n).fold(1L) { acc, i -> (acc * i) % m }
}

Measured memory_bytes: 36312
#include <bits/stdc++.h>
using namespace std;
 
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define MOD 1000000007
 
#define trace1(x)                    cout <<#x<<": "<<x<< endl;
#define trace2(x, y)                 cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define trace3(x, y, z)              cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define trace4(a, b, c, d)           cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
 
typedef long long ll;
ll n,k;
ll a[101];
ll pos1(ll fr,ll bk)
{
    if((fr+bk)>k || (fr+bk)>n)
    return 0;
    ll cnt=0;
    ll i;
    vector<ll> v;
    for(i=0;i<fr;i++)
    {
        v.pb(a[i]);
    }
    for(i=0;i<bk;i++)
    {
        v.pb(a[n-i-1]);
    }
    sort(all(v));
    ll rem=k-(fr+bk);
    for(i=0;i<v.size();i++)
    {
        if(i<rem && v[i]<0)
        continue;
        cnt+=v[i];
    }
    return cnt;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    ll i,j,m;
    cin>>n>>k;
    for(i=0;i<n;i++)
    cin>>a[i];
    ll maxi=0;
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=n-i;j++)
        {
            maxi=max(maxi,pos1(i,j));
        }
    }
    cout<<maxi;
    return 0;
}

Measured memory_bytes: 256
/*
    Written by Nitrogens
    Desire for getting accepted!!
*/
#include <cstdio>
#include <ctime>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>
#include <bitset>
#include <stack>
#include <set>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

const int maxn = 3e3+5;
const int Mod = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const double e = exp(1);
const db PI = acos(-1);
const db ERR = 1e-10;

#define Se second
#define Fi first
#define pb push_back
#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl

char s[maxn], t[maxn];
ll dp[maxn][maxn];

pii route[maxn][maxn];
bool flag[maxn][maxn];

int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);

    scanf("%s", s + 1);
    scanf("%s", t + 1);

    int lens = strlen(s + 1);
    int lent = strlen(t + 1);

    for(int i = 1; i <= lens; i++)
    {
        for(int j = 1; j <= lent; j++)
        {
            if(s[i] == t[j])
            {
                dp[i][j] = dp[i - 1][j - 1] + 1;
                route[i][j] = make_pair(i - 1, j - 1);
                flag[i][j] = true;
            }
            else
            {
                if(dp[i - 1][j] > dp[i][j - 1]) route[i][j] = make_pair(i - 1, j);
                else                            route[i][j] = make_pair(i, j - 1);
                dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
            }
        }
    }

    int x = lens, y = lent;
    stack <char> st;
    while(x && y)
    {
        //dbg3(x, y, s[x]);
        //dbg(flag[x][y]);
        if(flag[x][y])    st.push(s[x]);
        int tx = route[x][y].first;
        int ty = route[x][y].second;
        x = tx, y = ty;
    }

    while(!st.empty())
    {
        printf("%c", st.top());
        st.pop();
    }


    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


Measured memory_bytes: 150144
# -*- coding: utf-8 -*-
#rea and blac
h,w=1,1

count=0

def search(x,y):
    #マップの外側か壁の場合は何もしない
    #print(x,y)
    global count
    if x<0 or x>w-1 or y<0 or y>h-1 or map_data[y][x]=='#':
 
        return
        
    
    #以前に到達していたら何もしない
    if reached[y][x]:
         return

    reached[y][x]=1
    count+=1
    #print("aa")



    search(x+1,y)#右
    search(x-1,y)#左
    search(x,y+1)#上
    search(x,y-1)#下
    



while h!=0 and w!=0: 

    count=0
    #グラフの入力方法------

    w,h=map(int ,raw_input().split())
    if h==0 and w==0:
        break

    map_data = [[0]*w for _ in range(h)]
    reached = [[0]*w for _ in range(h)]
    for i in range(h):
        ct = raw_input()
        #print(len(ct))
        for j in range(w):
            map_data[i][j] = ct[j]
            if ct[j]=="@":
                sx=j
                sy=i

    #------



    search(sx,sy)

    print(count)
    count=0
    w=1
    h=1



Measured memory_bytes: 4764
import sys


def main():
    A, B, C = [int(x) for x in sys.stdin.readline().split()]
    if A < B and A < C and C < B:
        print("Yes")
    elif A > B and A > C and C > B:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2568
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();

    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let ws = buf.split_whitespace()
        .map(|x| x.parse::<usize>().unwrap())
        .collect::<Vec<_>>();

    let mut dif_min = 100000;
    for t in 0..n {
        let mut less_sum = 0;
        let mut great_sum = 0;
        for w in 0..n {
            if w <= t {
                less_sum += ws[w];
            }
            else {
                great_sum += ws[w];
            }
        }
        let dif = std::cmp::max(less_sum, great_sum) - std::cmp::min(less_sum, great_sum);
        dif_min = std::cmp::min(dif_min, dif);
    }

    println!("{}", dif_min);
}


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

using namespace std;
typedef long long int ll;

int main()
{
	
	ll n,k;cin>>n>>k;vector <ll> freq(200,0);
	for(ll i=1;i<=k;i++)
	{
		ll d;
		cin>>d;
		for(ll j=1;j<=d;j++){ll a;cin>>a;freq[a]++;}
	}
	ll cnt=0;
	for(ll i=1;i<=n;i++){if(freq[i]==0)cnt++;}
		
	cout<<cnt;
}


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

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

    return gcd(b, a%b);
}

int main(){
    while(true){
        int a, b;
        cin >> a >> b;

        if(cin.eof())
            break;

        int g = gcd(a, b);

        cout << g << ' ' << a/g*b << endl;
    }
    
    return 0;
}


Measured memory_bytes: 3084
package main

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

type ByValue []float64

func (s ByValue) Len() int           { return len(s) }
func (s ByValue) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s ByValue) Less(i, j int) bool { return s[i] < s[j] }

func input() string {
	var s string
	_, _ = fmt.Scan(&s)
	return s
}

func inputLn() string {
	var s string
	_, _ = fmt.Scanln(&s)
	return s
}

func inputByScanner(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func convListStrToInt(strList []string) []int {
	intList := make([]int, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = intV
	}
	return intList
}

func convListStrToFloat(strList []string) []float64 {
	intList := make([]float64, len(strList))
	for k, v := range strList {
		intV, _ := strconv.Atoi(v)
		intList[k] = float64(intV)
	}
	return intList
}

func main() {
	n, _ := strconv.Atoi(input())
	total := 0
	for i := n-1; i > 0; i-- {
		total += i
	}
	fmt.Println(total)
}


Measured memory_bytes: 640
import java.io.*;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        new Main().run();
    }

    void solve() {
        int H = in.nextInt();
        int W = in.nextInt();
        int[][] matrix = new int[H+2][W+2];
        String[] source = new String[H+1];
        for (int i  = 0 ; i < H+2 ; i++) {
            Arrays.fill(matrix[i], 0);
        }
        for (int i = 1 ; i <= H ; i++) {
            source[i] = in.nextToken();
        }
        for (int i = 1 ; i <= H ; i++) {
            for (int j = 1 ; j <= W ;j++) {
                if (source[i].charAt(j-1) == '#') {
                    matrix[i-1][j-1]++;
                    matrix[i-1][j]++;
                    matrix[i-1][j+1]++;
                    matrix[i][j-1]++;
                    matrix[i][j+1]++;
                    matrix[i+1][j-1]++;
                    matrix[i+1][j]++;
                    matrix[i+1][j+1]++;
                }
            }
        }
        for (int i = 1 ; i <= H ; i++) {
            for (int j = 1 ; j <= W ;j++) {
                if (source[i].charAt(j - 1) == '#') {
                    out.print('#');
                } else {
                    out.print(matrix[i][j]);
                }
            }
            out.println("");
        }
    }

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

}

Measured memory_bytes: 22356