akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int c[4][4];

void solve() {
    int a[4] = {0}, b[4] = {0};
    for (int i = 0; i < 100; ++i) {
        a[1] = i;
        b[1] = c[1][1] - a[1];
        a[2] = c[2][1] - b[1];
        b[2] = c[2][2] - a[2];
        a[3] = c[3][2] - b[2];
        b[3] = c[3][3] - a[3];
        bool flag = true;
        if (a[1] + b[1] != c[1][1]) flag = false;
        if (a[1] + b[2] != c[1][2]) flag = false;
        if (a[1] + b[3] != c[1][3]) flag = false;
        if (a[2] + b[1] != c[2][1]) flag = false;
        if (a[2] + b[2] != c[2][2]) flag = false;
        if (a[2] + b[3] != c[2][3]) flag = false;
        if (a[3] + b[1] != c[3][1]) flag = false;
        if (a[3] + b[2] != c[3][2]) flag = false;
        if (a[3] + b[3] != c[3][3]) flag = false;

        if (flag) {
            printf("Yes\n");
            return;
        }
    }
    printf("No\n");
}

int main() {
    for (int i = 1; i <= 3; ++i) {
        for (int j = 1; j <= 3; ++j) {
            cin >> c[i][j];
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 3576
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=100000;

int n;
int a[MAXN]; char op[MAXN-1];



void run() {
	scanf("%d",&n); REP(i,n) { scanf("%d",&a[i]); if(i!=n-1) scanf(" %c",&op[i]); }

	ll sum=0; REP(i,n) sum+=a[i];
	ll ret=a[0]; REP(i,n-1) if(op[i]=='+') ret+=a[i+1]; else ret-=a[i+1];
	ll sumneg=0;
	int at=0; while(at<n-1&&op[at]=='+') ++at;
	while(at<n-1) {
		int to=at+1; ll sumpos=0; while(to<n-1&&op[to]=='+') sumpos+=a[to+1],++to; if(to>=n-1) break;
		ll cur=sum-2*(sumneg+a[at+1]+sumpos); if(cur>ret) ret=cur;
		sumneg+=a[at+1]; at=to;
	}
	printf("%lld\n",ret);
}

int main() {
	run();
	return 0;
}


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

string rotato(string s) {
    return s.substr(1) + s[0];
}


int main() {
    string s, t; cin >> s >> t;
    for (int i=0; i<s.size(); i++) {
        if (s == t) {
            cout << "Yes" << endl;
            return 0;
        }
        s = rotato(s);
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
int main(){
  int A,B,C;
  str S1,S2,S3;
  vector<int>N(3);
  cin>>N.at(0)>>N.at(1)>>N.at(2);
  sort(N.begin(),N.end());
  cout<<N.at(0)+N.at(1)<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const int dx[4] = { 0, -1, 1, 0 };
const int dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}

template<class T1, class T2> void chmin(T1 &a, T2 b) { if (a>b)a = b; }

template<class T1, class T2> void chmax(T1 &a, T2 b) { if (a<b)a = b; }
template<class T>
void Add(T &a, const T &b, const T &mod = 1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}
////////////////////////////////////////

int main() {
	int N;
	cin >> N;
	vector<ll>V(N);
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		V[i] = a - (i + 1);
	}
	sort(V.begin(), V.end());
	int key = N / 2;
	ll sum = 0;
	for (int i = 0; i < N; ++i) {
		sum += abs(V[i] - V[key]);
	}
	cout <<sum<< endl;
	return 0;
}

Measured memory_bytes: 1792
n = int(input())
x = list(map(int, input().split()))

for i in range(n):
    x[i] = (x[i], i)

x.sort()

answers = [x[n//2 - 1][0]] * n

ans = x[n//2][0]
for i in range(n//2):
    answers[x[i][1]] = ans

for i in answers:
    print(i)

Measured memory_bytes: 37044
import std.stdio;
import std.ascii;
import std.conv;
import std.string;
import std.algorithm;
import std.range;
import std.functional;
import std.math;
import core.bitop;
import std.numeric;

void main()
{
    auto nk = readln.split.to!(long[]);
    auto n = nk[0];
    auto k = nk[1];
    long a;
    long b;
    foreach (i; 1 .. n + 1)
    {
        if (i % k == 0)
        {
            a++;
        }
    }
    if (k % 2 == 0)
    {
        foreach (i; 1 .. n + 1)
        {
            if (i % k == k / 2)
            {
                b++;
            }
        }
    }

    (a ^^ 3 + b ^^ 3).writeln;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#define ll long long
using namespace std;

int main(void){
    ll n, m, ans, cnt;
    cin >> n >> m;
    if(n%3==0||m%3==0){
        cout << 0 << endl;
        return 0;
    }
    ans = m*n;
    ll cnt1=n>>1, cnt2=m>>1;
    cnt1 = n-cnt1;
    cnt2 = m-cnt2;
    ll a=cnt1/2*m, b=cnt1*(m>>1);
    ll c=max(a, b);
    cnt = (n-cnt1)*m - max(cnt1/2*m, cnt1*(m>>1));
    ans = min(ans, cnt);

    cnt = (m-cnt2)*n - max(cnt2/2*n, cnt2*(n>>1));
    ans = min(ans, cnt);

    cnt1 = n-n/3;
    cnt = (m-m/2)*cnt1 - (n-cnt1)*m;
    ans = min(ans, cnt);

    cnt2 = m-m/3;
    cnt = (n-n/2)*cnt2 - (m-cnt2)*n;
    ans = min(ans, cnt);

    cnt1 = ceil(n*1.0/3);
    cnt1 = n-cnt1;
    cnt = (n-cnt1)*m - (m/2)*cnt1;
    ans = min(ans, cnt);

    cnt2 = ceil(m*1.0/3);
    cnt2 = m-cnt2;
    cnt = (m-cnt2)*n - (n/2)*cnt2;
    ans = min(ans, cnt);

    if(m>=3) ans = min(ans, n);
    if(n>=3) ans = min(ans, m);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
a=[1,3,5,7,8,10,12]
b=[4,6,9,11]
c=[2]
x,y=[int(i) for i in input().split()]
if (x in a) and (y in a):
    print("Yes")
elif (x in b) and (y in b):
    print("Yes")
elif (x in c) and (y in c):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include<functional>
using namespace std;
#define ll long long

int main(){
  int P,Q,R;
   cin >> P >> Q >> R;

  int S,T,U;
  int answer;
  S = P + Q;
  T = Q + R;
  U = R + P;

  answer = min(min(S,T),min(T,U));
  cout << answer << endl;

}

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

int main(){
    int n;
    cin >> n;
    int m;
    m = n/7;
    int count = 0;
    for(int i=1;i<=m;i++){
        if((n-i*7)%4==0){
            count++;
            break;
        }
    }
    if(n%7==0) count++;
    if(n%4==0) count++;
    if(count != 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
import sys
a = list(raw_input())
b = list(raw_input())

if len(a) > len(b):
    print 'GREATER'
    sys.exit(0)
if len(b) > len(a):
    print 'LESS'
    sys.exit(0)

if len(a) == len(b):
    flag = 'equal'
    for i in xrange(len(a)):
        if a[i] > b[i]:
            flag = 'greater'
            break
        if b[i] > a[i]:
            flag = 'less'
            break
    print flag.upper()

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define UM unordered_map
#define ALL(a) (a).begin(), (a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
typedef pair<ll, ll> pii;
struct Edge
{
    ll s, t, d;
};
typedef vector<vector<Edge>> Graph;
typedef vector<pii> vpii;
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;
}

int N, A, B, C;
vi l;
int ans = 1000000000;
void dfs(int idx, int sum_A, int sum_B, int sum_C, int cnt)
{
    if (sum_A != 0 and sum_B != 0 and sum_C != 0)
        chmin(ans, abs(sum_A - A) + abs(sum_B - B) + abs(sum_C - C) + cnt * 10);

    if (idx == N)
        return;

    if (sum_A == 0)
        dfs(idx + 1, sum_A + l[idx], sum_B, sum_C, cnt);
    else
        dfs(idx + 1, sum_A + l[idx], sum_B, sum_C, cnt + 1);
    if (sum_B == 0)
        dfs(idx + 1, sum_A, sum_B + l[idx], sum_C, cnt);
    else
        dfs(idx + 1, sum_A, sum_B + l[idx], sum_C, cnt + 1);
    if (sum_C == 0)
        dfs(idx + 1, sum_A, sum_B, sum_C + l[idx], cnt);
    else
        dfs(idx + 1, sum_A, sum_B, sum_C + l[idx], cnt + 1);
    dfs(idx + 1, sum_A, sum_B, sum_C, cnt);
}

//制約見ましょう。全探索です。
int main()
{
    cin >> N >> A >> B >> C;
    l.resize(N);
    REP(i, N)
    {
        cin >> l[i];
    }
    dfs(0, 0, 0, 0, 0);
    cout << ans << endl;
    //system("pause");
}

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

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

    struct Pos {
        int x, y;
        Pos() : Pos(0, 0) {}
        Pos(int x, int y) : x(x), y(y) {}
    };

    int N, M;
    std::cin >> N >> M;
    std::vector<Pos> students(N);
    std::vector<Pos> checkpoints(M);
    for (auto& i : students)std::cin >> i.x >> i.y;
    for (auto& i : checkpoints)std::cin >> i.x >> i.y;
    for (int i = 0; i < N; ++i) {
        int min = INT_MAX;
        int ans = -1;
        for(int j = 0;j<M;++j){
            int dis = abs(checkpoints[j].x - students[i].x) + abs(checkpoints[j].y - students[i].y);
            if (dis < min) {
                min = dis;
                ans = j + 1;
            }
        }
        std::cout << ans << std::endl;
    }

}

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

namespace x
{
    class Program
    {
        static void Main(string[] args)
        {
            var maxLen = IOUtils.ReadInt();
            var text = Console.ReadLine();

            System.Console.WriteLine(text.Length <= maxLen ? text : text.Substring(0, maxLen) + "...");


        }
    }
    
    static class IOUtils
    {
        public static (int a, int b) Read2Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1]);
        }
        public static (int a, int b, int c) Read3Ints()
        {
            var vals = ReadInts();
            return (vals[0], vals[1], vals[2]);
        }
        public static IEnumerable<int[]> ReadIntLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadInts();
            }
        }
        public static IEnumerable<long[]> ReadLongLines(int count)
        {
            for (int i = 0; i < count; i++)
            {
                yield return ReadLongs();
            }
        }
        public static int ReadInt()
        {
            return int.Parse(Console.ReadLine());
        }
        public static long ReadLong()
        {
            return long.Parse(Console.ReadLine());
        }
        public static ulong ReadUlong()
        {
            return ulong.Parse(Console.ReadLine());
        }
        public static int[] ReadInts()
        {
            return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();
        }
        public static long[] ReadLongs()
        {
            return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
        }

        public static void WriteNums(params int[] nums)
        {
            Console.WriteLine(string.Join(" ", nums));
        }
    }
}


Measured memory_bytes: 27484
//ll f(ll n){
//    set<pll> a;
//    rep(i,0,n)
//        rep(j,0,n-i)
//            a.insert(mp(i^j,i+j));
//    return sz(a);
//}
//map<ll,ll> saved;
//ll g(ll m){
//    if(m==0) return 1;
//    if(m==1) return 2;
//    if(saved.count(m))
//        return saved[m];
//    if(m%2 == 0)
//        return saved[m] = (2*g(m/2-1)+g(m/2))%MOD;
//    return saved[m] = (2*g(m/2) + g(m/2-1))%MOD;
//}
//ll _(){
//    ll n;
//    cin >> n;
//    return g(n);
//
//}
#include <map>
#include <set>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <vector>
#include <utility>
#include <iostream>
#include <string>
#define mp make_pair
#define REP_INT(i,l,r) for(int i = l; i <= r; ++i)
#define GET_REP_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define rep(...) GET_REP_MACRO(__VA_ARGS__,REP_ANY,REP_INT)(__VA_ARGS__)
#define all(v) (v).begin(), (v).end()
#define sz(v) ll(v.size())
#define T1 template<typename T> static
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
const ll MOD = 1e9 + 7;
T1 ostream& operator<<(ostream& stream, const vector<T>& t);
T1 istream& read(T, T, istream& = cin);
ll f(ll n){
    set<pll> a;
    rep(i,0,n)
        rep(j,0,n-i)
            a.insert(mp(i^j,i+j));
    return sz(a);
}
map<ll,ll> saved;
ll g(ll m){
    if(m==0) return 1;
    if(m==1) return 2;
    if(saved.count(m))
        return saved[m];
    if(m%2 == 0)
        return saved[m] = (2*g(m/2-1)+g(m/2))%MOD;
    return saved[m] = (2*g(m/2) + g(m/2-1))%MOD;
}
ll _(){
    ll n;
    cin >> n;
    return g(n);
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
        cout << _() << '\n';
}


Measured memory_bytes: 256
import java.util.Scanner


object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n, k = sc.nextInt()
    val xs = new Array[Int](n)
    
    for (i <- xs.indices) {
      xs(i) = sc.nextInt()
    }
    
    var ans = 1000000000
    
    for (i <- 0 until n - k + 1) {
      val y = xs(i)
      val z = xs(i + k - 1)
      val distance = math.abs(z - y)
      if (math.min(y, z) > 0) {
        ans = math.min(ans, distance + math.min(y, z))
      } else if (math.max(y, z) < 0) {
        ans = math.min(ans, distance - math.max(y, z))
      } else {
        val m = math.min(math.abs(y), math.abs(z))
        ans = math.min(ans, distance + m)
      }
    }
    
    println(ans)
  }
  
  def printArray[T](arr: Array[T]): Unit = {
    for (i <- arr.indices) {
      print(s"${arr(i)} ")
    }
    println()
  }
}


Measured memory_bytes: 49388
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef tuple<ll, ll, ll> tl3;



const int BIG_NUM = 1e9;
const ll INF = 1000000000000000000;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;



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

}


Measured memory_bytes: 3592
x1, y1, x2, y2 = [int(x) for x in input().split()]
dx = x2-x1
dy = y2-y1
x3 = x2 + (-dy)
y3 = y2 + (dx)
dx = x3-x2
dy = y3-y2
x4 = x3 + (-dy)
y4 = y3 + (dx)
print(x3, y3, x4, y4)


Measured memory_bytes: 38256
#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 fs first
#define sc second
#define fr(i, a, b) for(int i = a ; i < b ; i++)
#define frr(i, a, b) for(int i = a ; i >= b ; i--)
#define tr(it, var) for(__typeof(var.begin()) it = var.begin(); it != var.end(); it++)
#define trr(rit, var) for(__typeof(var.rbegin()) rit = var.rbegin(); rit != var.rend(); rit++)
#define its(x) static_cast< ostringstream & >( ( ostringstream() << dec << x ) ).str() // int to string
#define fill1(a, c, x) fr(_I, 0, (c)) (a)[_I] = (x);
#define fill2(a, r, c, x) fr(_I, 0, (r)) fr(_J, 0, (c)) (a)[_I][_J] = (x);
#define sz(x) ((int)(x).size())
#define deb(x) cout << #x" = " << x << '\n';

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;

int n, mn, mx;

int miin(int a, int b) {
	if(abs(a - 0) < abs(b - 0)) return a;
	return b;
}

int maax(int a, int b) {
	if(abs(a - 0) > abs(b - 0)) return a;
	return b;
}

int main() {
//    freopen("input.in", "r", stdin);
	scanf("%d", &n);
	fr(i, 0, n) {
		int x;
		scanf("%d", &x);
		if(i == 0) {
			mn = mx = x;
		}
		else {
			mn = min(mn, x);
			mx = max(mx, x);
		}
	}
	printf("%d", mx-mn);
	return 0;
}

Measured memory_bytes: 256
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto ab = readln.split.to!(long[]);
    auto k2 = ab[0] + ab[1];
    writeln(k2%2 == 1 ? "IMPOSSIBLE" : (k2 / 2).to!string);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=101000;
const int K=20;
double EPS=1e-7;
typedef long long ll;

map<string,int> mp;


int32_t main()	
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
 	mp["SUN"]=7;
 	mp["MON"]=1;
 	mp["TUE"]=2;
 	mp["WED"]=3;
 	mp["THU"]=4;
 	mp["FRI"]=5;
 	mp["SAT"]=6;
 	string s;
 	cin>>s;
 	if(s=="SUN")
 		cout<<7<<"\n";
 	else
 	cout<<mp["SUN"]-mp[s]<<"\n";
    return 0;
}

Measured memory_bytes: 256
n,a = gets.split(" ").map!{|i| i.to_i}
min = 1000
frag = true
n.times do 
  c, t = gets.split(" ").map{|i| i.to_i}
  if t <= a 
    frag = false
    if min > c
      min = c
    end
  end
end
if frag == true
  puts "TLE"
else puts min
end

Measured memory_bytes: 1788
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		String[] input = sc.next().split("");
		for (int i = 0; i < input.length; i++) {
			if(input[i].equals("1")) {
				System.out.print("9");
			}else {
				System.out.print("1");
			}
		}
	}
}

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

#define pb push_back
#define ff first
#define ss second
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ii pair<int,int>
#define vi vector<int>
#define vll vector<ll>
#define vii vector<ii>

using namespace std;

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n,k,ans=0;
	cin >> n >> k;
	for(int i=0,x;i<n;++i){
		cin >> x;
		ans+=(x>=k);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			if ((n | m) == 0)
				break;
			int[] map = new int[n];
			for (int i = 0; i < n; i++)
				map[i] = scanner.nextInt();
			int[] a = new int[m];
			for (int i = 0; i < m; i++)
				a[i] = scanner.nextInt();
			int x = 0;
			for (int i = 0; i < m; i++) {
				x = Math.min(n - 1, a[i] + x);
				x += map[x];
				if (x >= n - 1) {
					System.out.println(i + 1);
					break;
				}
			}

		}
	}
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  int n, a, b, c, d;
  string s;
  Solver(LL n) : n(n){};

  void solve() {
    cin >> a >> b >> c >> d;
    --a, --b, --c, --d;
    cin >> s;
    vector<int> p(n), q(n);
    for (int i = 1; i < n; ++i) {
      if (s[i - 1] == '#' && s[i] == '#') p[i] = 1;
    }
    for (int i = 1; i < n - 1; ++i) {
      if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.') q[i] = 1;
    }
    for (int i = 1; i < n; ++i) {
      p[i] += p[i - 1];
      q[i] += q[i - 1];
    }
    if (c < d) {
      if (p[a] == p[c] && p[b] == p[d])
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    } else {
      if (p[a] == p[c] && p[b] == p[d] && q[d] > q[b - 1])
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 2128
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <utility>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <iterator>
#include <random>
#include <fstream>
#include <chrono>
#include <math.h>
#include <cctype>
using namespace std;
#define int long long
#define forn(i, n) for (int i = 0; i < n; ++i)
const int mod = 998244353;
string s;
vector<vector<int>>dp;
bool chk;
int ans;
vector<int>u;
vector<vector<int>>g;
void dfs(int v, int prev){
    if(prev != -1) {
        for (int i = 0; i < 26; i++)
            dp[v][i] += dp[prev][i];
    }
    dp[v][s.at(v) - 'a']++;
    cout << "added at v = " << v << " " << s.at(v) << "\n";
    for(int i = 0 ;i < 26; i++) {
        if(dp[v][i] == 5)
            cout << v << " " << i << "\n";
        ans = max(ans, dp[v][i]);
    }
    u[v]=1;
    for(auto x: g[v])
    {
        if(u[x])
            chk = false;
        else {
            dfs(x, v);
        }
    }
    // как сделать путь
    // если развернуть вершины
    // тогда цикл мы все равно найдем
    // а иначе другие циклы будут уничтожены
    // тогда начиная с вершин куда никто не входит запускаем дфс
    // тогда мы можем добавить к текущей один из вариантов
    // тогда просто передаем массив
    // когда не может пойти
}
int32_t main() {
    // vs code
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    bool ch = false;
    int k;
    cin >> k;
    int temp = 0;
    for(int i = 1; i <= 1e7; i++){
        temp *= 10;
        temp += 7;
        temp %= k;
        if(temp == 0)
        {
            cout << i << "\n";
            return 0;
        }
    }
    cout << -1 << "\n";
    return 0;
}

Measured memory_bytes: 3644
import math
N = int(input())
a = list(map(int,input().split()))
x = sum(a)/N
if math.ceil(x)-x < x-math.floor(x):
    x = math.ceil(x)
else:
    x = math.floor(x)
ans = 0
for i in range(N):
    ans += (a[i]-x)**2
print(ans)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(){
	string s;
	cin>>s;
	while(s!="0"){
		int sum=0;
		for(int i=0; i<s.length(); i++){
			sum+=s[i]-'0';
		}
		cout<<sum<<endl;
		cin>>s;
	}
}


Measured memory_bytes: 3160
#include <iostream>
using namespace std;
  
int main()
{
    int h, w;
     
    do
    {
        cin  >> h >> w;
        if(h != 0 && w != 0)
        {
            for(int i = 1; i <= h; i++)
            {
                if(i == 1 || i == h)
                {
                    int n = 0;
                    while(n < w)
                    {
                        cout << '#';
                        n++;
                    }
                    cout << endl;
                }
                else
                {
                    int n = 1;
                    while(n <= w)
                    {
                        if(n == 1 || n == w)
                            cout << '#';
                        else
                            cout << '.';
                        n++;
                    }
                    cout << endl;
                }
             
            }
            cout << endl;
        }
    }while(h != 0 && w != 0);
     
    return 0;
}

Measured memory_bytes: 3048
#include <iostream>
#include <algorithm>
#include <cmath>
#include <complex>
#include <vector>
using namespace std;
typedef complex<double> P;

int main() {
  int Tc;
  cin >> Tc;
  while(Tc--) {
    P p1, p2;
    double r1, r2;
    cin >> p1.real() >> p1.imag() >> r1;
    cin >> p2.real() >> p2.imag() >> r2;
    double d = abs(p1-p2);
    int res;
    if(d < r1-r2) res = 2;
    else if(d < r2-r1) res = -2;
    else if(d > r1+r2) res = 0;
    else res = 1;
    cout << res << endl;
  }
  return 0;
}

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

int main()
{
  string s, t;
  cin >> s >> t;
  vector<char> sv, tv;
  for (auto&& e : s) sv.push_back(e);
  for (auto&& e : t) tv.push_back(e);
  sort(begin(sv), end(sv));
  sort(begin(tv), end(tv), greater<>());
  cout << (sv < tv ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
def main():
    n = int(input())
    a = list(map(int, input().split()))
    nn = (n*(n+1))//2
    sum_ = sum(a)
    a += [a[0]]
    cnt = sum_//nn
    if sum_ % nn != 0:
        print("NO")
        return 0
    ans = 0
    for i in range(n):
        p = a[i]-a[i+1]+cnt
        if p % n != 0 or p//n<0:
            print("NO")
            return 0
        ans += p//n
    if ans == cnt:
        print("YES")
    else:
        print("NO")


main()

Measured memory_bytes: 14292
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<vector>

using namespace std;

typedef long long ll;
#define N (1<<19)
struct foo{
	ll a,b;
};

bool comp(const foo &a,const foo &b){
	return a.b>b.b;
}

struct seg{
	ll sum,maxs;
};

int n;
foo in[300001];
int cnt[100001];
seg dat[1<<20];

void add(int k,int a){
	cnt[k]+=a;
	k+=N-1;
	dat[k].sum=(k-N+1)*cnt[k-N+1];
	if(cnt[k-N+1]>0)dat[k].maxs=k-N+1;
	else dat[k].maxs=0;
	while(k>0){
		k=(k-1)/2;
		dat[k].sum=dat[k*2+1].sum+dat[k*2+2].sum;
		dat[k].maxs=max(dat[k*2+1].maxs,dat[k*2+2].maxs);
	}
}

bool C(ll mid){
	memset(dat,0,sizeof(dat));
	memset(cnt,0,sizeof(cnt));
	int cnt=0;
	for(int i=0;i<n;i++){
		add(in[i].a,1);
		cnt++;
		ll v=dat[0].sum;
		//printf("%lld %lld %d\n",v,in[i].b,cnt);
		if(v>in[i].b*mid){
			cnt--;
			add(dat[0].maxs,-1);
			//printf("%lld %lld %d\n",dat[0].sum,in[i].b,cnt);
		}
		if(cnt>=mid)return true;
	}
	return false;
}


int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld%lld",&in[i].a,&in[i].b);
	sort(in,in+n,comp);
	ll lb=0,ub=n+1;
	while(ub-lb>1){
		ll mid=(lb+ub)/2;
		//printf("%lld\n",mid);
		if(C(mid))lb=mid;
		else ub=mid;
	}
	printf("%lld\n",lb);
	return 0;
}

Measured memory_bytes: 22672
#include <iostream>
#include <vector>
#include <string>

enum { TOP, FRONT, RIGHT, LEFT, BACK, BOTTOM };
const int NUM_OF_EYE = 6;

using namespace std;

class Dice {

  vector<int> eye;

public:
  Dice(int init_status[])
  {
    for (int i = 0; i < NUM_OF_EYE; i++) {
      eye.push_back(init_status[i]);
    }
  }
  
  ~Dice()
  {
  }

  void roll_n()
  {
    int tmp;
    tmp = eye[TOP];
    eye[TOP] = eye[FRONT];
    eye[FRONT] = eye[BOTTOM];
    eye[BOTTOM] = eye[BACK];
    eye[BACK] = tmp;
  }
  
  void roll_e()
  {
    int tmp;
    tmp = eye[TOP];
    eye[TOP] = eye[LEFT];
    eye[LEFT] = eye[BOTTOM];
    eye[BOTTOM] = eye[RIGHT];
    eye[RIGHT] = tmp;
  }

  void roll_w()
  {
    int tmp;
    tmp = eye[TOP];
    eye[TOP] = eye[RIGHT];
    eye[RIGHT] = eye[BOTTOM];
    eye[BOTTOM] = eye[LEFT];
    eye[LEFT] = tmp;
  }

  void roll_s()
  {
    int tmp;
    tmp = eye[TOP];
    eye[TOP] = eye[BACK];
    eye[BACK] = eye[BOTTOM];
    eye[BOTTOM] = eye[FRONT];
    eye[FRONT] = tmp;
  }

  int get_eye(int position)
  {
    return eye[position];
  }
};


int main()
{
  int init_status[NUM_OF_EYE];
  
  for (int i = 0; i < NUM_OF_EYE; i++) {
    cin >> init_status[i];
  }

  Dice d(init_status);

  string op;
  
  cin >> op;

  for (int i = 0; i < op.length(); i++) {
    if (op[i] == 'N') {
      d.roll_n();
    } else if (op[i] == 'E') {
      d.roll_e();
    } else if (op[i] == 'W') {
      d.roll_w();
    } else if (op[i] == 'S') {
      d.roll_s();
    }
  }
  
  std::cout << d.get_eye(TOP) << std::endl;
  
}



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

using namespace std;

int main() {
    int N;
    string s;
    set<string> S;

    cin >> N;

    rep(i, N) {
        cin >> s;
        S.insert(s);
    }
    cout << S.size() << endl;
}

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

namespace ProblemB
{
    class Program
    {
        static void Main(string[] args)
        {
            var str = Console.ReadLine();
            var first = int.Parse(str.Substring(0, 2));
            var second = int.Parse(str.Substring(2, 2));
            var isFirstMM = 1 <= first && first <= 12;
            var isSecondMM = 1 <= second && second <= 12;

            if (isFirstMM && isSecondMM)
                Console.WriteLine("AMBIGUOUS");
            else if (isFirstMM)
                Console.WriteLine("MMYY");
            else if (isSecondMM)
                Console.WriteLine("YYMM");
            else
                Console.WriteLine("NA");
        }
    }
}


Measured memory_bytes: 11092
/* 
 * Project: AtCoder Beginners Contest 102 A - Multiple of 2 and N
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/06/07
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
using namespace std;

int n;

void solve() {

    if (n & 1)
        printf("%d\n", n*2);
    else
        printf("%d\n", n);

}

int main() {

    scanf("%d", &n);

    solve();

}

Measured memory_bytes: 256
function main(input) {
  const args = input.split("\n");
  let h, w;
  [h, w] = args[0].split(" ").map((x) => Number(x));

  let table = Array.from(new Array(h + 1), () => new Array(w + 1).fill(0));

  for (let y = 0; y < h; y++) {
    let tmp = args[y + 1].split(" ").map((x) => Number(x));
    let sum = 0;
    for (let x = 0; x <= w; x++) {
      if (x != w) {
        table[y][x] = tmp[x];
        sum += tmp[x];
      } else {
        table[y][x] = sum;
      }
    }
  }

  for (let x = 0; x <= w; x++) {
    let sum = 0;
    for (let y = 0; y < h; y++) {
      sum += table[y][x];
    }
    table[h][x] = sum;
  }

  for (let y = 0; y <= h; y++) {
    let output = "";
    for (let x = 0; x <= w; x++) {
      output += String(table[y][x]);
      if (x != w) {
        output += " ";
      }
    }
    console.log(output);
  }
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 18152
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main() {
    int N;
    cin >> N;

    cout << (N + 1) / 2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>

#define pb push_back
#define ll long long
using namespace std;
vector<string> a;
int n,l;

int calc(int v){
  char c=a[l][v];
  char cc;
  int r;
  l++;v++;
  //cout<<":"<<c<<endl;
  if(l<n-1&&(a[l][v]=='+'||a[l][v]=='*')) r=calc(v);
  else{
    if(c=='*') r=1;
    else if(c=='+') r=0;
    else r=c-'0';
  }
  if(l>=n) return r;
  if(c=='+'){
    while(a[l].size()==v+1){
      cc=a[l][v];
      //cout<<cc<<endl;
      if(l+1<n&&(cc=='+'||cc=='*')) r+=calc(v);
      else {r+=cc-'0';l++;}
      if(l==n) break;
    }
  }
  else if(c=='*'){
    while(a[l].size()==v+1){
      cc=a[l][v];
      if(l+1<n&&(cc=='+'||cc=='*')) r*=calc(v);
      else {r*=cc-'0';l++;}
      if(l==n) break;
    }
  }
  //cout<<r<<endl;
  return r;
}

int main(){
  int i;
  while(cin >> n,n){
    string s;
    a.clear();
    for(i=0;i<n;i++){
      cin >> s;
      a.pb(s);
    }
    l=0;
    cout << calc(0) << endl;
  }
}

Measured memory_bytes: 3124
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int n;
    cin >> n;
    
    for(int i = 0; i < 8; i++){
        if(n < pow(2,i+1) ){
            cout << pow(2,i) << endl;
            break;
        }
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
using namespace std;
#define dd c=getchar()
inline int read(){
	int a=0,b=1,dd;
	while(!isdigit(c)){if(c=='-')b=-b;dd;}
	while(isdigit(c)){a=a*10+c-'0';dd;}
	return a*b;
}
inline void print(int x){
	static int c[23];
	static int n;
	if(x==0){
		putchar('0');
		return;
	}
	if(x<0){
		putchar('-');
		x=-x;
	}
	n=0;
	while(x>0){
		c[n++]=x%10+'0';
		x/=10;
	}
	while(n-->0){
		putchar(c[n]);
	}
}
#undef dd
const int N=1e5+3;
vector<int>e[N];
int n,m,xa[N],ya[N],top;
bool vis[N];
int dfs(int u,int fa){
	vis[u]=1;
	int ans=0;
	for(unsigned i=0;i<e[u].size();i++){
		int&v=e[u][i];
		if(v==fa)continue;
		if(vis[v]){
			if(v<u){
				ans^=1;
				top++;
				xa[top]=u;
				ya[top]=v;
			}
		}else if(!dfs(v,u)){
			ans^=1;
			top++;
			xa[top]=u;
			ya[top]=v;
		}else{
			top++;
			xa[top]=v;
			ya[top]=u;
		}
	}
	return ans;
}
int main(){
	n=read();
	m=read();
	for(int i=1;i<=m;i++){
		int x=read();
		int y=read();
		e[x].push_back(y);
		e[y].push_back(x);
	}
	if(dfs(1,0)){
		puts("-1");
		return 0;
	}
	for(int i=1;i<=top;i++){
		print(xa[i]);
		putchar(' ');
		print(ya[i]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 15488
#include<stdio.h>
int main(){
  int h,w;
  int i;
  scanf("%d %d",&h,&w);
  char a[h+1][w+1];
  for(i=0;i<h;i++){
    scanf("%s",a[i]);
  }
  for(i=0;i<h;i++){
    printf("%s\n%s\n",a[i],a[i]);
  }
  return 0;
}


Measured memory_bytes: 128
import math

n = int(input())
aL = list(map(int, input().split(" ")))

l = []
r = []
for i in range(n):
    if i % 2 == 0:
        l.append(aL[i])
    else:
        r.append(aL[i])

if n % 2 == 0:
    print(*list(reversed([*reversed(l), *r])))
else:
    print(*reversed(l), *r)


Measured memory_bytes: 30964
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
S = [list(sys.stdin.readline().rstrip()) for _ in range(N)]

for s in S:
    s.sort()
S.sort()
ans = 0
cnt = 0
for s, t in zip(S, S[1:]):
    if s == t:
        cnt += 1
    else:
        if cnt > 0:
            ans += cnt * (cnt + 1) // 2
        cnt = 0
if cnt > 0:
    ans += cnt * (cnt + 1) // 2
print(ans)


Measured memory_bytes: 95068
from itertools import *
n,m=map(int,input().split())
M=m
a=[1]
for i in range(2,int(m**.5)+1):
    while m%i==0:
        m//=i
        a+=[i]
if m!=1:a+=[m]
ans=1
for i in range(len(a)):
    for b in combinations_with_replacement(set(a),i):
        c=1
        for j in b:c*=j
        if c>=n and M%c==0:ans=max(ans,M//c)
print(ans)

Measured memory_bytes: 9444
N = 100
WHITE = 0
GRAY = 1
BLACK = 2

d = [-1] * N
f = [-1] * N

def dfs_visit(n, u, tt, color):
    global d
    global f
    color[u] = GRAY
    tt += 1
    d[u] = tt
    for v in range(n):
        if M[u][v] == 0:
            continue
        if color[v] == WHITE:
            tt = dfs_visit(n, v, tt, color)
    color[u] = BLACK
    tt += 1
    f[u] = tt
    return tt

def dfs(n):
    global d
    global f
    color = []
    for u in range(n):
        color.append(WHITE)
    tt = 0

    for u in range(n):
        if color[u] == WHITE:
            tt = dfs_visit(n, u, tt, color)
    
    for u in range(n):
        print(u+1, d[u], f[u])

n = int(input())

M = [[0] * n for _ in range(n)]

for i in range(n):
    I = list(map(int, input().split()))
    u = I[0] - 1
    k = I[1]
    for j in range(k):
        v = I[j+2] - 1
        M[u][v] = 1

#print(M)

dfs(n)


Measured memory_bytes: 5800
#include <stdio.h>
int main(void)
{
	float a, b;
	
	while (scanf("%f %f", &a, &b) != EOF){
		if (a < 35.5 && b < 71){
			printf("AAA\n");
		}
		else if (a < 37.5 && b < 77){
			printf("AA\n");
		}
		else if (a < 40 && b < 83){
			printf("A\n");
		}
		else if (a < 43 && b < 89){
			printf("B\n");
		}
		else if (a < 50 && b < 105){
			printf("C\n");
		}
		else if (a < 55 && b < 116){
			printf("D\n");
		}
		else if (a < 70 && b < 148){
			printf("E\n");
		}
		else {
			printf("NA\n");
		}
	}
	
	return (0);
}

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

using namespace std;

#define ll long long
#define ull unsigned long long
#define __ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)

const int maxn = 2e5 + 10;
const int maxm = 1e4 + 10;
const ll mod = 998244353;

int main() {
    __;
    int a[100], n, b[100];
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b + 1, b + 1 + n);
    int ct = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i] != b[i])++ct;
    }
    if (ct > 2)cout << "NO" << endl;
    else cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R;


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

	cin >> N >> M >> K;
	if (N % 2 && M % 2 && K % 2) {
		cout << min({ N*M,N*K,M*K }) << endl;
	}
	else cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	void c() {
		int n = sc.nextInt();
		int[] d = new int[n];
		for(int i = 0;i < n;i ++) {
			d[i] = sc.nextInt();
		}
		Arrays.sort(d);
		System.out.println(d[n/2] - d[n/2-1]);
	}
	
	public static void main(String[] args) {
		new Main().c();
	}

}

Measured memory_bytes: 51452
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <string>
#include <stack>
 
using namespace std;
 
#define f(i,a,b) for(int i=a;i<b;i++)
#define fll(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(int i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define vvi vector<vector<int> >
#define ss second
#define ff first
#define ll long long
#define lld long double
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pq priority_queue< int >
#define pqll priority_queue< ll >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define INF 1000000000
#define NINF -1000000000
 
ll maxll(ll a , ll b ){
    return a > b ? a : b;
}
 
ll minll(ll a , ll b){
    return a > b ? b : a;
}

// bool check(ll z){
//     ll temp = k;
//     // cout << z << endl;
//     f(i , 0 , n){
//         ll sub = (ll)z * a[i];
//         if (sub > b[i])
//         temp -= (sub -b[i]);
//         if (temp < 0){
//             return 0;
//         }
//     }
//         // cout << z << endl;
//     sol = z;
//         return 1;
// }

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

// void print_vi(vi a){
//     for (int i: a){
//         cout << i << " " ;
//     }
//     cout << endl;
// }

// Best algo to find maximum sum subarray (contiguous)
// ll kadane (vl a){
//     ll curr = 0 , maxi = 0;
//     f(i , 0 , a.size()){
//         curr = max(a[i] , curr + a[i]);
//         maxi = max(maxi , curr);
//     }
//     return maxi;
// }

// Method to get the factors of a big number here a[j] = factors of number j
// ll x;
// cin >> x;
// vl a(x+1 , 0);
// f( i , 1 , x+1){
//     for (int j = i ; j < x+1 ; j+= i){
//         a[j]++;
//     }
// }


void solve(){
    
    string a , b;
    cin >> a >> b;
    vvi dp(a.length()+1 , vi(b.length()+1 , 0));

    f( i , 1 , a.length()+1){
        f(j , 1 , b.length()+1)
        {
            if (a[i-1] == b[j-1]){
                dp[i][j] = 1 + dp[i-1][j-1];
            }
            else{
                dp[i][j] = max(dp[i-1][j] , dp[i][j-1]);
            }
        }
    }
    
    int temp = dp[a.length()][b.length()];
    string ans = "";
    int i = a.length() , j = b.length();
    while(i > 0 && j > 0){
        if ( a[i - 1] == b[j - 1]){
            i--;
            j--;
            ans.pb(a[i]);
        }
        else if (dp[i-1][j] > dp[i][j-1])
        i--;
        else
        j--;
    }

    reverse(ans.begin() , ans.end());
    cout << ans << endl;
    
}

 
int main(){
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.tie(nullptr);
 
 
    
    int t = 1;
    // cin >> t;
    
    while(t--){
        
        solve();
    }
}

Measured memory_bytes: 38580
#include <bits/stdc++.h>
using namespace std;
const int INF=1e9+5;
int main()
{
	int n;scanf("%d",&n);
	vector<int> v(n,0);
	for(int& i:v)
	scanf("%d",&i);
	int maxi=INF;
	vector<int> dp(n,INF);
	
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	
	for(int i=2;i<n;i++){
		for(int j:{i-1,i-2}){
			if(j<n){
				dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
			}
		}
	}
	
	//for(int i=0;i<n;i++)	cout<<dp[i]<<" ";cout<<endl;
	
	cout<<dp[n-1]<<endl;
			
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define MAX 100010
#define MOD 998244353
using namespace std;

int arr[MAX];
int cnt[MAX];

inline int prod(int a, int b)
{
	return (long long)a * b % MOD;
}

int power(int a, int n)
{
	if (!n) return 1;
	int mid = power(a, n / 2);
	mid = prod(mid, mid);
	if (n % 2) mid = prod(mid, a);
	return mid;
}

int main(void)
{
	int N;
	cin >> N;
	int mmax = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> arr[i];
		cnt[arr[i]]++;
		mmax = max(mmax, arr[i]);
	}
	if (arr[0] != 0 || cnt[0] != 1)
	{
		cout << 0 << endl;
		return 0;
	}
	int ans = 1;
	for (int i = 0; i <= mmax; i++)
	{
		if (!cnt[i])
		{
			cout << 0 << endl;
			return 0;
		}
	}
	for (int i = 0; i < mmax; i++) ans = prod(ans, power(cnt[i], cnt[i + 1]));
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#pragma GCC optimze("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pp pair<ll,ll>
#define ppp pair<ll,pp >
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char* name, Arg1&& arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
typedef tree<pp,null_type,less<pp>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define ld long double
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rep(i,a,b) for(ll i=a;i<b;i+=1)
#define sz(v) (ll)(v.size())
#define hell (ll)1000000007
#define slld(x) scanf("%lld",&x)
ll t=1, tt;
const ll inf=1e18;
inline ll mult(ll x,ll y){x%=hell;y%=hell;return (1LL*x*y)%hell;}
inline ll add(ll x,ll y){x+=y;return x%hell;}
inline ll powMod(ll base,ll expo){
	if(base==0)return 0;
	ll ans=1;
	while(expo){
		if(expo&1)ans=mult(ans,base);
		base=mult(base,base); 
		expo>>=1;
	}
	return ans;
}
vector<ll> pre,dp;
void solve(){
	ll n;
	cin>>n;
	vector<vector<ll> > a(n,vector<ll>(n));
	rep(i,0,n)
		rep(j,0,n)
			cin>>a[i][j];
	pre.resize(1<<n);
	rep(mask,0,1LL<<n){
		rep(i,0,n){
			if((mask>>i)&1){
				rep(j,i+1,n){
					if((mask>>j)&1)pre[mask]+=a[i][j];
				}
			}
		}
	}
	dp.resize(1<<n,-inf);
	dp[0]=0;
	rep(mask,0,1LL<<n){
		vector<ll> not_taken;
		rep(i,0,n)
			if(!((mask>>i)&1))
				not_taken.pb(i);
		ll nn=sz(not_taken);
		rep(mask2,0,1LL<<nn){
			ll cur_mask=0;
			rep(j,0,sz(not_taken))
				if((mask2>>j)&1)cur_mask^=(1LL<<not_taken[j]);
			dp[mask^cur_mask]=max(dp[mask^cur_mask],dp[mask]+pre[cur_mask]);
		}
	}
	cout<<dp[(1<<n)-1];
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   	//cin>>t;
   	tt=t;
    while(t--){
        solve();
        if(t)cout<<"\n";
    }
    return 0 ;
}


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

float distance(vector<vector<int>> A,int p,int q){
  int dim = A.front().size();
  float dissqu = 0;
  for(int i=0;i<dim;i++){
    dissqu += pow(abs(A[p][i]-A[q][i]),2);
  }
  float dis = sqrt(dissqu);
  return dis;
}

int main(){
  int N,D;
  cin >> N >> D;
  vector<vector<int>> X (N, vector<int>(D));
  for(int i=0;i<N;i++){
    for(int j=0;j<D;j++){
      cin >> X[i][j];
    }
  }
  int count = 0;
  for(int k=0;k<N;k++){
    for(int l=k+1;l<N;l++){
      float dis = distance(X,k,l);
      if(ceil(dis)==floor(dis)){
        count ++;
      }
    }
  }
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 256
from collections import deque

h, w = map(int, input().split())
s = [input() for _ in range(h)]

d = [[-1] * w for _ in range(h)]


def bfs():
    sx, sy = 0, 0
    q = deque()
    q.append([sx, sy])
    d[sy][sx] = 0
    dxy = [[1, 0], [-1, 0], [0, 1], [0, -1]]

    while q:
        ux, uy = q.popleft()
        for dx, dy in dxy:
            vx = ux + dx
            vy = uy + dy

            if 0 <= vx <= w - 1 and 0 <= vy <= h - 1 \
                and s[vy][vx] == "." and d[vy][vx] == -1:
                q.append([vx, vy])
                d[vy][vx] = d[uy][ux] + 1


bfs()
mn = d[h-1][w-1]

if mn == -1:
    ans = -1
else:
    cnt = 0
    for i in range(h):
        for j in range(w):
            if s[i][j] == ".":
                cnt += 1

    ans = cnt - mn - 1

print(ans)


Measured memory_bytes: 3316
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n,a[100010],ans[100010]={},m=0;
    vll v;
    map<ll,ll> mp,cnt;
    cin>>n;
    rep(i,n){
        cin>>a[i];
        v.pb(a[i]);
        m=max(m,a[i]);
        cnt[a[i]]++;
        if(mp[a[i]]==0) mp[a[i]]=i+1;
    }
    sort(all(v));
    ERASE(v);
    reverse(all(v));
    if(v[v.size()-1]!=1){
        v.pb(1);
        mp[1]=1;
    }
    ll now=cnt[m],index=mp[m];
    ans[index]+=now;
    rep2(i,1,(ll)v.size()){
        ans[index]+=now*(v[i-1]-v[i]-1);
        index=min(index,mp[v[i]]),now+=cnt[v[i]];
        ans[index]+=now;
        // cout<<v[i]<<" "<<index<<" "<<now<<endl;
    }
    rep2(i,1,n+1){
        cout<<ans[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 15860