akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;

int H, W;
char board[1010][1010], pat[2][2];

int matching(int x, int y) {
  for(int dx=0; dx<2; dx++) {
    for(int dy=0; dy<2; dy++) {
      int nx = x + dx, ny = y + dy;
      if(pat[dx][dy] != board[nx][ny]) return 0;
    }
  }
  return 1;
}

int solve(int x, int y) {
  int sum = 0;
  for(int p=x-1; p<=x; p++) {
    for(int q=y-1; q<=y; q++) {
      if(p < 0 || p >= H || q < 0 || q >= W) continue;
      sum += matching(p, q);
    }
  }
  return sum;
}

int main() {
  cin >> H >> W;
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      cin >> board[i][j];
    }
  }

  for(int i=0; i<2; i++) {
    for(int j=0; j<2; j++) {
      cin >> pat[i][j];
    }
  }

  int ans = 0;
  for(int i=0; i<H-1; i++) {
    for(int j=0; j<W-1; j++) {
      ans += matching(i, j);
    }
  }

  int max_diff = 0;
  string joi = "JOI";
  for(int i=0; i<H; i++) {
    for(int j=0; j<W; j++) {
      int prev = solve(i, j);
      char c = board[i][j];
      for(int k=0; k<3; k++) {
        board[i][j] = joi[k];
        int changed = solve(i, j);
        max_diff = max(max_diff, changed - prev);
        board[i][j] = c;
      }
    }
  }

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



Measured memory_bytes: 4160
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

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

			int h = sc.nextInt();
			int w = sc.nextInt();

			boolean[][] maze = new boolean[h+2][w+2];

			for(int i = 0 ; i < h ; i++ ) {
				String cols = sc.next();

				for(int j = 0 ; j < w ; j++ ) {
					maze[i+1][j+1] = (cols.charAt(j) == '.');
				}
			}

			// guards
			for(int i = 0 ; i < h ; i++ ) {
				maze[i][0] = false;
				maze[i][w+1] = false;
			}

			for(int j = 0 ; j < w ; j++ ) {
				maze[0][j] = false;
				maze[h+1][j] = false;
			}

			int maxResult = 0;

			for(int i = 0 ; i < h ; i++ ) {				
				for(int j = 0 ; j < w ; j++ ) {
					int result = walkCount(i+1, j+1, h, w, maze);
//					System.out.println(String.format("%d, %d, %d", i+1, j+1, result));
					if ( maxResult < result) {
						maxResult = result;
					}
				}
			}

			System.out.println(maxResult);
		}
	}

	private static int walkCount(int initY,int initX, int h, int w, boolean[][] maze) {

		// 0 --> -1,0
		// 1 --> 0,1
		// 2 --> 1,0
		// 3 --> 0,-1
		if ( !maze[initY][initX] ) {
			return 0;
		}
		
		
		int[][] steps = new int[h+2][w+2];
		for(int i = 0 ; i < h ; i++ ) {
			for(int j = 0 ; j < w ; j++ ) {
				steps[i+1][j+1] = Integer.MAX_VALUE;				
			}
		}

		PriorityQueue<SearchStep> pq = new PriorityQueue<>(new Comparator<SearchStep>() {
			@Override
			public int compare(SearchStep o1, SearchStep o2) {			
				return Integer.compare(o1.step, o2.step);
			}			
		});

		steps[initY][initX] = 0;
		SearchStep initialSearch = new SearchStep(initY, initX, 0);
		pq.add(initialSearch);
		while(true) {			

			SearchStep ss = pq.poll();
			if ( ss == null) {
				break;
			}
			
//			System.out.println(String.format(" ## %d,%d,%d", ss.y,ss.x,ss.step));

			for(int i = 0 ; i < 4 ; i++ ) {
				int dy = i % 2 == 0 ? i - 1 : 0;
				int dx = i % 2 == 1 ? 2 - i : 0;

				int x = ss.x;
				int y = ss.y;
				int step = ss.step;
				
//				System.out.println(String.format(" --> %d,%d,step value:%d, %b", y+dy,x+dx,steps[y+dy][x+dx], maze[y+dy][x+dx]));

				if ( steps[y+dy][x+dx] > step + 1 && maze[y+dy][x+dx]) {
					steps[y+dy][x+dx] = step + 1;
					pq.add(new SearchStep(y+dy, x+dx, step+1));
				}
			}
		}

		int max = 0;
		for(int i = 0 ; i < h ; i++ ) {
			for(int j = 0 ; j < w ; j++ ) {
				if ( steps[i+1][j+1] > max && maze[i+1][j+1]) {
					max = steps[i+1][j+1];
				}
			}
		}
		
		return max;
	}

	private static class SearchStep {

		SearchStep(int y,int x, int step) {
			this.y = y;
			this.x = x;
			this.step = step;
		}
		public int y;
		public int x;
		public int step;


	}
}

Measured memory_bytes: 31248
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

A,B = map(int,S().split())

print(A*B)

Measured memory_bytes: 61732
#include<iostream>
#include<math.h>
#include<iomanip>
#include<vector>
#include<algorithm>
#include<queue>
#include<string>
#include<stdlib.h>
#include<stack>
using namespace std;
#define PI 3.14159265358979
typedef  long long ll; //9.2e18
#define rep(i,n) for(int i=0;i<n;i++)
#include<set>
int main(void)
{
    ll a,b,c;
    cin>>a>>b>>c;

    ll d = c-a-b;


    if(4*a*b<d*d&&d>0) 
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;


}

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

#define ll long long
vector< int > v, ans(10004, -1);

void solve(){
	string s; cin>>s;
	for(char &i : s){
		if(i == '?'){
			i = 'D';
		}
	}
	cout<<s<<endl;
}

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


Measured memory_bytes: 3748
def main():
    N = int(input())
    A = list(map(int, input().split()))
    # verification
    x = 1
    mx = [0] * (N+1)
    for i, a in enumerate(A):
        if i != N and x <= a:
            print(-1)
            return
        if i == N and x < a:
            print(-1)
            return
        x -= a
        mx[i] = x
        x *= 2
    ans = 0
    edge = 0
    for i in range(N+1)[::-1]:
        a = A[i]
        edge = min(edge, mx[i])
        ans += edge + a
        edge += a
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 705332
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(n) begin(n), end(n)
using ll = long long;
using namespace std;

int main(){
	int n;
	cin >> n;
	double ans = 0;
	vector<pair<double, double>> vp(n);
	vector<int> v(n);
	rep(i, n){
		int a, b;
		cin >> a >> b;
		vp.at(i) = make_pair(a, b);
		v.at(i) = i;
	}
	int count = 0;
	do{
		// if(count == 2)rep(i, n){
		// 	if(i != 0) cerr << " ";
		// 	cerr << v.at(i);
		// }
		// cerr << endl;
		double temp = 0;
		rep2(i, 1, n){
			int vi = v.at(i);
			int vm = v.at(i-1);
			double x = (vp.at(vi).first - vp.at(vm).first) * (vp.at(vi).first - vp.at(vm).first);
			double y = (vp.at(vi).second - vp.at(vm).second) * (vp.at(vi).second - vp.at(vm).second);
			temp += sqrt(x + y);
			// if(count == 2) cerr << x << " " << y << " " << sqrt(x + y) << endl;
		}
		// cerr << temp << endl;
		ans += temp;
		count++;
	}while(next_permutation(v.begin(), v.end()));
	ans /= count;
	printf("%.8f\n", ans);
	return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
string to_str(ll x){string res; while(x)res+=('0'+(x%10)),x/=10; reverse(ALL(res)); return res;}
template<class T> inline bool chmax(T& a,T b){ if(a<b){a=b;return 1;}return 0; }
template<class T> inline bool chmin(T& a,T b){ if(a>b){a=b;return 1;}return 0; }
//template end

void make2(int a,int sz,vector<int>& v){
   vector<int> add(sz,a/sz);
   add.back()+=a%sz;
   rep(i,0,sz)v.push_back(add[i]);
}

vector<int> make(int a,int b){
   vector<int> sub,res(a); int sz=a%b;
   make2(a/b+1,sz,sub); make2(-a/b-2,b-sz,sub);
   rep(i,0,a)res[i]=sub[i%b]; return res;
}

int main(){
   int H,W,h,w; scanf("%d%d%d%d",&H,&W,&h,&w);
   if(H%h==0&&W%w==0){printf("No\n"); return 0;}
   printf("Yes\n");
   bool f=(H%h);
   if(f){
      vector<int> a=make(H,h);
      rep(i,0,H){
         rep(j,0,W)printf("%d ",a[i]);
         puts("");
      }
   }
   else{
      vector<int> a=make(W,w);
      rep(i,0,H){
         rep(j,0,W)printf("%d ",a[j]);
         puts("");
      }
   }
   return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

int main() {
  ll n;
  while (cin >> n) {
    ll result = 1000;
    for (ll i = 1; i * i <= n; ++i) {
      if (n % i) continue;
      ll j = n / i;
      ls(result, (ll)(max(to_s(i).length(), to_s(j).length())));
    }
    cout <<result << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

import static java.lang.Integer.max;

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

        int a, b;
        a = sc.nextInt();
        b = sc.nextInt();
        if (max(a, b) <= 8) {
            System.out.println("Yay!");
        }
        else {
            System.out.println(":(");
        }
    }
}


Measured memory_bytes: 21844
#include <stdio.h>
#define FOR(variable,a,b) for(variable=(a);variable<(b);variable++)

int main(){
    // import phase
    int i, j;
    
    // output phase
    FOR(i, 1, 10) {
        FOR(j, 1, 10) {
            printf("%dx%d=%d\n", i, j, i*j);
        }
    }
    return 0;
}

Measured memory_bytes: 524
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
    int N; cin >> N;
    map<int, int> v1 {};
    map<int, int> v2 {};

    for(int i = 0; i < N / 2; ++i){
        int a; cin >> a;
        auto itr = v1.find(a);
        if( itr != v1.end() ) {
            v1[a] += 1;
        } else {
            v1[a] = 1;
        }
        cin >> a;
        itr = v2.find(a);
        if( itr != v2.end() ) {
            v2[a] += 1;
        } else {
            v2[a] = 1;
        }
    }

    int max1 = 0;
    int total1 = 0;
    int key1 = -1;
    for(auto itr = v1.begin(); itr != v1.end(); ++itr) {
        if(max1 < itr->second){
            key1 = itr->first;
            max1 = itr->second;
        }
        total1 += itr->second;
    }

    int max2 = 0;
    int total2 = 0;
    for(auto itr = v2.begin(); itr != v2.end(); ++itr) {
        if(itr->first != key1){
            max2 = max(max2, itr->second);
        }
        total2 += itr->second;
    }

    int ans = total1 - max1 + total2 - max2;

    max1 = 0;
    total1 = 0;
    key1 = -1;
    for(auto itr = v2.begin(); itr != v2.end(); ++itr) {
        if(max1 < itr->second){
            key1 = itr->first;
            max1 = itr->second;
        }
        total1 += itr->second;
    }

    max2 = 0;
    total2 = 0;
    for(auto itr = v1.begin(); itr != v1.end(); ++itr) {
        if(itr->first != key1){
            max2 = max(max2, itr->second);
        }
        total2 += itr->second;
    }

    int ans2 = total1 - max1 + total2 - max2;

    printf("%d\n", min(ans, ans2));
    return 0;
}

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

int main() {
  vector<int> x(5);
  rep(i, 5) cin >> x[i];

  int ans;
  rep(i, 5) {
    if (x[i] == 0) {
      ans = i + 1;
    }
  }

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


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(int i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const int max_n = 1e5 + 9;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}
int main()
{
    string s;
    cin >> s;
    if(s == "ABC")cout << "ARC";
    else cout << "ABC";
    return 0;
}

Measured memory_bytes: 3624
n = gets.chomp.to_i
zahyou = readlines.map{|elem| elem.chomp.split(" ").map(&:to_f)}

def calc_distance (p,q)
  ((p[0]-q[0])**2 + (p[1]-q[1])**2)**(0.5)
end

distance = zahyou.combination(2).map{|elem| calc_distance(elem[0],elem[1])}
puts distance.inject(&:+)*2.0/n


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

int main(){
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    for(int i = 0; i + 2 < N; i++){
        if(S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C') ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
function Main(input) {
    const args = input.split('\n');
    const s = args[0];
    const t = args[1];
    var count = 0;
    for(var i = 0; i < s.length; i++){
        if(s.charAt(i) == t.charAt(i)){
            count++;
        }
    }
    
    console.log(count);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include <stdio.h>
#include <unistd.h>
#include <string.h>

int		main(void)
{
	int h,w;
	scanf("%d%d", &h,&w);
	char str[h + 1][w + 1];
	int i;

	i = 0;
	while (i < h)
	{
		scanf("%s", str[i]);
		i++;
	}
	i = 0;
	while (i < h)
	{
		printf("%s\n", str[i]);
		printf("%s\n", str[i]);
		i++;
	}
	return (0);
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int inf = (1 << 29);

template < class T > inline void fastScan(T &x) {
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

ll dp[102][102];

vector < pii > v;

int isPrime(int n){
  if(n == 1){
    return 0;
  }
  for(int i = 2; i * i <= n; i++){
    if(n % i == 0){
      return 0;
    }
  }
  return 1;
}

void P(int x, int n){
  int how = 0;
  while(n > 0){
    how += n / x;
    n /= x;
  }
  v.pb(mp(x, how));
}

ll go(int pos, int hand){
  if(hand == 75){
    return 1;
  }
  if(pos >= v.size()){
    return (hand == 75);
  }
  if(dp[pos][hand] != -1){
    return dp[pos][hand];
  }
  ll ret = go(pos + 1, hand);
  for(int i = 1; i <= v[pos].se; i++){
    if(hand * (i + 1) <= 75) {
      ret += go(pos + 1, hand * (i + 1));
    }
  }
  return dp[pos][hand] = ret;
}

int main(){
  int n;
  fastScan(n);
  for(int i = 2; i <= n; i++){
    if(isPrime(i)){
      P(i, n);
    }
  }
  memset(dp, -1, sizeof dp);
  ll ans = go(0, 1);
  printf("%lld\n", ans);
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>

using namespace std;

struct Node
{
    int key;
    Node *right,*left,*parent;
};

Node *root,*NIL;

void insert(int k)
{
    Node *y=NIL;
    Node *x=root;
    Node *z;

    z=(Node*)malloc(sizeof(Node));
    z->key=k;
    z->left=NIL;
    z->right=NIL;

    while (x!=NIL)
    {
        y=x;
        if (z->key < x->key)
        {
            x=x->left;
        }
        else
        {
            x=x->right;
        }
    }
    
    z->parent=y;
    if (y==NIL)
    {
        root=z;
    }
    else
    {
        if(z->key < y->key)
        {
            y->left=z;
        }
        else
        {
            y->right=z;
        }
    }
}

Node* find(Node *u,int k)
{
    while (u!=NIL && k!=u->key)
    {
        if (k<u->key)u=u->left;
        else u=u->right;
    }
    
    return u;
}

void inorder(Node *u)
{
    if(u==NIL)return;
    inorder(u->left);
    printf(" %d",u->key);
    inorder(u->right);
}

void preorder(Node *u)
{
    if(u==NIL)return;
    printf(" %d",u->key);
    preorder(u->left);
    preorder(u->right);
}

int main()
{
    int n,i,x;
    string com;

    scanf("%d",&n);

    for (int i = 0; i < n; i++)
    {
        cin>>com;
        if(com=="insert")
        {
            scanf("%d",&x);
            insert(x);
        }
        else if(com=="print")
        {
            inorder(root);
            printf("\n");
            preorder(root);
            printf("\n");
        }
        else if (com=="find")
        {
            scanf("%d",&x);
            Node *t=find(root,x);
            if(t!=NIL)printf("yes\n");
            else printf("no\n");
        }
        
    }

    return 0;
}



Measured memory_bytes: 22012
#include <bits/stdc++.h>
using namespace std;
struct liter
{
    double cap;
    long long value;
}p[4];

bool comp(const liter&p1,const liter&p2)
{
    if(p1.value/p1.cap<=p2.value/p2.cap)
    {
        return true;
    }
    else
    {
        return false;
    }
}
int main(void)
{
    long long N;
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    p[0].cap=0.25;
    cin>>p[0].value;

     p[1].cap=0.5;
    cin>>p[1].value;

     p[2].cap=1.0;
    cin>>p[2].value;

     p[3].cap=2.0;
    cin>>p[3].value;

    cin>>N;
    sort(p,p+4,comp);
    long long  sum=0;
    int t=int(N/p[0].cap);
    N=N-t*p[0].cap;
    sum+=p[0].value*t;
    if(N>0)
    {
        t=int(N/p[1].cap);
        N=N-t*p[1].cap;
        sum+=p[1].value*t;
    }
    if(N>0)
    {
         t=int(N/p[2].cap);
        N=N-t*p[2].cap;
        sum+=p[2].value*t;
    }
    if(N>0)
    {
        t=int(N/p[3].cap);
        N=N-t*p[3].cap;
        sum+=p[3].value*t;
    }

    printf("%lld\n",sum);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1000000007;
template<class T> void print(const T& t){ cout << t << endl; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
  string s;
  cin >> s;
  if(sz(s)%2==1){
    s.erase(sz(s) - 1);
  }
  while(sz(s)>=0){
    s.erase(sz(s) - 2);
    string t = s;
    t.erase(sz(s) / 2);
    string u = t + t;
    if(s==u){
      print(sz(s));
      break;
    }
  }
}

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

int main(){
  int n; cin>>n;
  int log,m=0;
  vector<int> x(n);
  for(int i=0;i<n;i++){
    cin>>x[i];
    if(m<x[i]){
      m=x[i];
      log =i;
    }
  }sort(x.begin(),x.end());
  for(int i=0;i<n;i++){
    if(i==log){
      cout<<x[n-2]<<endl;
    }else{
      cout<<x[n-1]<<endl;
    }
  }
}

Measured memory_bytes: 2432
import scala.io.Source.stdin

object Main {
  def getSum(i:Int,a:Int,b:Int,sum:Int):Int =
    if(i<0) sum else getSum(i-1,(a%b)*10,b,sum+(a/b))

  def main(args:Array[String]) = {
    stdin.getLines.foreach { s =>
      val n = s.split(" ").map(_.toInt)
      val a = if(n(0) >= n(1)) n(0)-(n(0)/n(1))*n(1) else n(0)
      println(getSum(n(2),a,n(1),0))
    }
  }
}

Measured memory_bytes: 43696
#include <iostream>
#include <sstream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <regex>

#define FOR(i,x,y) for(int i=(x);i<(y);i++)
#define RFOR(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define REP(i,x) for(int i=0;i<(x);i++)
#define RREP(i,x) for(int i=(x)-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

using namespace std;

const int MAX = 100000;
int N,K,L;
int p[MAX],q[MAX],r[MAX],s[MAX];

struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size, -1) { }
    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }
    bool findSet(int x, int y) {
        return root(x) == root(y);
    }
    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }
    int size(int x) {
        return -data[root(x)];
    }
};

void solve() {
    UnionFind roads(N);
    UnionFind rails(N);
    REP(i,K){
        roads.unionSet(p[i]-1,q[i]-1);
    }
    REP(i,L){
        rails.unionSet(r[i]-1,s[i]-1);
    }
    map<pair<int,int>,int> towns;
    REP(i,N){
        int road,rail;
        road = roads.root(i);
        rail = rails.root(i);
        if(towns.count(pair<int,int>(road,rail))) towns[pair<int,int>(road,rail)] += 1;
        else towns[pair<int,int>(road,rail)] = 0;
    }
    REP(i,N){
        int road,rail;
        road = roads.root(i);
        rail = rails.root(i);
        cout << towns[pair<int,int>(road,rail)] + 1;
        if(i < N-1) cout << " ";
    }
    cout << "\n";
}

signed main() {
    // to shorten execution time for iostream
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N >> K >> L;
    REP(i,K) cin >> p[i] >> q[i];
    REP(i,L) cin >> r[i] >> s[i];
    solve();
    return 0;
}


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

using namespace std;

using ll = long long;

#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

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 gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, k;
	cin >> n >> k;
	int x[n];
	rep(i, n) cin >> x[i];
	
	int min_dist = inf;
	rep(i, n - k + 1) {
		int left = x[i];
		int right = x[i + k - 1];
		int dist;
		if (left < 0 and 0 < right) {
			dist = abs(left) + abs(right) + min(abs(left), abs(right));
		} else {
			dist = max(abs(left), abs(right));
		}
		chmin(min_dist, dist);
	}
	
	cout << min_dist << endl;
	
	return 0;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const double INF = 1e10;
struct edge {
	int from;
	int to;
	int d;
	int c;
	edge() {}
	edge(int from, int to,int d, int c) :from(from), to(to),d(d), c(c) {}
};

struct node {
	int n;
	int v;
	int rev;

	node() {}
	node(int n, int v, int rev) :n(n), v(v), rev(rev) {}

	bool operator ==(const node& o) const {
		return (n == o.n) && (v == o.v) && (rev == o.rev);
	}
};

int dv[3] = { -1,0,1 };

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, m;
	while (cin >> n >> m, n | m) {
		/* input */
		int s, g; cin >> s >> g;
		s--; g--;
		vector<vector<edge>> G(n);
		for (int i = 0; i < m;i++) {
			int x, y, d, c; cin >> x >> y >> d >> c;
			x--; y--;
			G[x].push_back(edge(x, y, d, c));
			G[y].push_back(edge(y, x, d, c));
		}

		/* initialize */
		const int MAX_V = 33;
		vector<vector<vector<double>>> dist(n,vector<vector<double>>(MAX_V,vector<double>(n,INF)));
		dist[s][0][s] = 0;
		queue<node> q;
		q.push(node(s, 0, s));

		/* solve */
		while (!q.empty()) {
			auto now = q.front(); q.pop();
			int now_n = now.n;
			int now_v = now.v;
			for (auto e : G[now_n]) {
				if (now.rev == e.to) continue;
				for (int i = 0; i < 3;i++) {
					if (now_v + dv[i] < 1) continue;
					if (now_v + dv[i] > e.c) continue;
					int next_v = now_v + dv[i];
					double cost = e.d / (double)next_v;
					if (dist[e.to][next_v][e.from] > dist[e.from][now_v][now.rev] + cost) {
						dist[e.to][next_v][e.from] = dist[e.from][now_v][now.rev] + cost;
						if (e.to == g && next_v == 1)continue;
						q.push(node(e.to, next_v, e.from));
					}
				}
			}
		}

		double ans = INF;
		for (int i = 0; i < n;i++) {
			ans = min(ans, dist[g][1][i]);
		}
		if (ans == INF) {
			cout << "unreachable" << endl;
		}
		else {
			cout << fixed << setprecision(7) << ans << endl;
		}
	}
}

Measured memory_bytes: 3584
# 高橋君の住む町の天気は、一日ごとに晴れ(Sunny)、くもり(Cloudy)、雨(Rainy)、晴れ、くもり、雨、… と周期的に変化します。
# 今日の天気を表す文字列 S が与えられるので、明日の天気を予測してください。

# 標準入力から明日の天気を表す文字列 S を取得する
today_weather = input()
tommorow_weather = 'I do not know. Sorry!!'

# 取得した入力 S を条件に従い出力する。
if today_weather == 'Sunny':
    tommorow_weather = 'Cloudy'
elif today_weather == 'Cloudy':
    tommorow_weather = 'Rainy'
elif today_weather == 'Rainy':
    tommorow_weather ='Sunny'

print(tommorow_weather)


Measured memory_bytes: 9020
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define brep(index,num) for(int index=num-1;index>=0;index--)
#define brep1(index,num) for(int index=num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
vint adj[1001];
bool seen[1001],finished[1001];
bool exist[1001][1001];
int pos=-1;
vint hist;
int dfs(int v,int p){
	seen[v]=1;
	hist.push_back(v);
	int flag=0;
	rep(i,(int)hist.size()-2){
		if(exist[hist[i]][hist.back()]){
			flag=1;
			break;
		}
	}
	for(int i=1;i<(int)hist.size()-1;i++){
		if(exist[hist.back()][hist[i]]){
			flag=1;
			break;
		}
	}
	/*printf("flag:%d  ",flag);
	rep(i,hist.size()){
		printf("%d ",hist[i]+1);
	}
	kaigyo;*/
	if(flag){
		hist.pop_back();
		finished[v]=1;
		return 0;
	}
	if(exist[hist.back()][hist[0]]){
		pos=hist[0];
		return 1;
	}
	for(auto nv:adj[v]){
		if(nv==p) continue;
		if(finished[nv]) continue;
		if(seen[nv]&& !finished[nv]){
			pos=nv;
			return 1;
		}
		dfs(nv,v);
		if(pos!=-1) return 1;
	}
	hist.pop_back();
	finished[v]=1;
	return 0;
}
int main(){
	int N,M,A[2002],B[2002];
	scan(N>>M);
	rep(i,M){
		scan(A[i]>>B[i]);
		A[i]--; B[i]--;
		adj[A[i]].push_back(B[i]);
		exist[A[i]][B[i]]=1;
	}
	rep(i,N){
		fill(seen,seen+N,0);
		fill(finished,finished+N,0);
		pos=-1;
		if(dfs(i,-1)==1){
			prin(0);
			return 0;
		}
	}
	prin(-1);
	return 0;
}


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

int main() {
    LL N,K;cin >> N >> K;
    LL ans = 0;
    if(K == 0){
        cout << N*N << endl;
    }
    else{
        for(int i = 1;i <= N;++i) {
            int tmp = N/i;
            int nokori = N-tmp*i;
            if(nokori > 0){
                if(nokori >= K)ans += nokori - K + 1;
            }
            if(i-K > 0)ans += (i-K)*tmp;
        }

        cout << ans << endl;
    }

}

Measured memory_bytes: 256
/**
 *  author: mahfuzz
 *  created: 30.04.2020
**/
 
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;

int main(int argc, char* argv[]){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    
    string curr, prev = "";
    bool flag = true;
    map<string, int> record;
    
    int n; cin >> n;
    while(n--){
        cin >> curr;
        if(!flag)
            continue;
        if(prev == ""){
            record[curr]++;
            prev = curr;
        }else if(prev[prev.size() - 1] == curr[0]){
            if(record[curr]){
                flag = false;
            }else{
                record[curr]++;
            }
            prev = curr;
        }else{
            flag = false;
        }
    }
    
    if(flag)
        cout << "Yes\n";
    else
        cout << "No\n";
        
    return 0;
}


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

string S;
vector<long long> numbers;

void bitfullsearch(const long long x)
{
    string tmp, num = "";

    for (long long bit = 0; bit < (1 << x); bit++)
    {
        tmp = S;
        for (long long j = 0; j < x; j++)
        {
            num.push_back(tmp.at(j));
            if (bit & (1 << j))
            {
                numbers.push_back(stoll(num));
                num = "";
            }
        }
        num.push_back(tmp.at(x));
        numbers.push_back(stoll(num));
        num = "";
    }
}

int main()
{
    cin >> S;

    bitfullsearch(S.length() - 1);

    long long sum = 0;

    for (long long i : numbers)
    {
        sum += i;
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cctype>
#include<algorithm>
using namespace std;
typedef long long ll;

const int maxn = 100 + 5;
const int mod = 1e9 + 7;

int qpow(int a,int k) { int ans = 1; for(;k > 0;k >>= 1,a = ((ll)a * a) % mod) if(k & 1) ans = ((ll)ans * a) % mod;return ans;}

int h[maxn] , w[maxn] , dp[maxn][maxn];

int main(){
	int n;
	scanf("%d",&n);
	for(int i = 1;i <= n;i++) scanf("%d",h + i) , w[i] = h[i];
	sort(w + 1,w + n + 1); int m = unique(w + 1,w + n + 1) - w - 1;
	for(int i = 1;i <= n;i++) h[i] = lower_bound(w + 1,w + m + 1,h[i]) - w;
	dp[0][0] = 1;
	for(int i = 1;i <= n;i++){
		for(int j = h[i] + 1;j <= h[i - 1];j++) dp[i][0] = (dp[i][0] + dp[i - 1][j] * 2 % mod) % mod;
		dp[i][0] = (dp[i][0] + dp[i - 1][0] * 2 % mod) % mod;
		for(int j = 1;j <= h[i];j++){
			dp[i][j] = (ll) dp[i - 1][j] * qpow(2,w[h[i]] - w[h[i - 1]]) % mod;
			if(h[i - 1] >= j) continue;
			if(j > 1) dp[i][j] = (dp[i][j] + (ll)dp[i - 1][0] * (qpow(2,w[j] - w[j - 1]) - 1) % mod * 2 % mod * qpow(2,w[h[i]] - w[j]) % mod) % mod;
			else dp[i][j] = (dp[i][j] + (ll)dp[i - 1][0] * (qpow(2,w[j]) - 2) % mod * qpow(2,w[h[i]] - w[j])) % mod;
		} 
	}
	int ans = 0;
	for(int i = 0;i <= m;i++) ans = (ans + dp[n][i]) % mod;
	printf("%d\n",ans);
	
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,i,j,r;
int main(){
 cin>>n;int a[n];
 for(auto &x:a)cin>>x;
 sort(a,a+n);
 for(;i<n;i++)a[i]==a[j]?:(r+=i-j-((i-j)<a[j]?0:a[j]),j=i);
 cout<<r+i-j-((i-j)<a[j]?0:a[j]);
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int main()
{
    IOS;
    //ll t;cin>>t;while(t--)
    {
        ll a,b,c,d,i,j,k,l,m,n,sum=0,temp=0,f=0,cnt=0;
        string s;
        cin>>s;
        if(s[0]=='R' && s[1]=='R' && s[2]=='R')
            cout<<3<<endl;
        else if((s[0]=='R' && s[1]=='R') || (s[1]=='R'&& s[2]=='R'))
            cout<<2<<endl;
        else if(s[0]=='R' || (s[1]=='R') || s[2]=='R')
            cout<<1<<endl;
        else cout<<0<<endl;



    }
}




Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
 
int main(){
    int n;
    double x[1001], y[1001], sum[1001], d = 0.0;
 
    cin >> n;
    for (int i = 0; i < n; i++)  cin >> x[i];
    for (int i = 0; i < n; i++)  cin >> y[i];
 
    for (int i = 0; i < n; i++){
        sum[i] = fabs(x[i] - y[i]);
    }
 
    d = 0.0;
    for (int i = 0; i < n; i++){
        d += sum[i];
    }
    printf("%lf\n", d);
 
    d = 0.0;
    for (int i = 0; i < n; i++){
        d += pow(sum[i], 2);
    }
    printf("%lf\n", sqrt(d));
 
    d = 0.0;
    for (int i = 0; i < n; i++){
        d += pow(sum[i], 3);
    }
    printf("%lf\n", pow(d, 1.0/3));
 
    d = 0.0;
    for (int i = 0; i < n; i++){
        if (sum[i] > d)
            d = sum[i];
    }
    printf("%lf\n", d);
 
    return 0;
}

Measured memory_bytes: 1304
from functools import reduce

# from collections import defaultdict


def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


def gcddd(*numbers):
    return reduce(gcd, numbers)


def reducef(x, y):
    return gcdd[(x, y)]


def gcd2(*numbers):
    return reduce(reducef, numbers)


K = int(input())
ans = 0
# gcdd=defaultdict()
gcdd = {}
for a in range(1, K + 1):
    for b in range(1, K + 1):
        if (a, b) not in gcdd:
            gcdd[(a, b)] = gcddd(a, b)

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            ans += gcd2(a, b, c)
print(ans)


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

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    sort(s1.begin(),s1.end());
    sort(s2.begin(),s2.end());
    reverse(s2.begin(), s2.end());
    if (s1 < s2){
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;

}

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

int sum(vector<int> vec, int P){
	int ans=0;
	for(auto xi : vec){
		ans += (xi - P)*(xi - P);
	}
	return ans;
}

int main() {
	int N;
	cin >> N;
	vector<int> X(N);
	for(int i=0;i<N;i++){
		cin >> X.at(i);
	}

	long long ans=1e18;
	for(int i=0;i<=100;i++){
		if(ans > sum(X, i)){
			ans = sum(X, i);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int n,d=0,c=0;
	cin>>n;
	for(int i=1;i<=n;i=i+2){
		d=0;
		for(int j=1;j<=i;j++){
			if(i%j==0)
			d++;
		}
		if(d==8)c++;
	}
	cout<<c<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static Scanner scan = new Scanner(System.in);
	public static int n;
	public static void main(String args[]){
		run();
	}
	static void run(){
		int n, firstPriceTmp, priceTmp;
		int minPrice, maxPrice;
		int maxBenefit, benefit;
		
		maxBenefit = -(1000000000 - 1);
		minPrice = 1000000000;
		maxPrice = 1;
		n = scan.nextInt();
		
		firstPriceTmp = scan.nextInt();
		for(int i = 1; i < n; i++){
			priceTmp = scan.nextInt();
			minPrice = Math.min(minPrice, firstPriceTmp);
			firstPriceTmp = priceTmp;
			benefit = priceTmp - minPrice;
			maxBenefit = Math.max(benefit, maxBenefit);
		}
		System.out.println(maxBenefit);
	}
}

Measured memory_bytes: 99736
N = int(input())
S = str(input())
K = int(input())
#N = 5
#S = "error"
S = list(S)
#K = 2
char = S[K-1]
for i in range(len(S)):
    if S[i] != char:
        S[i] = "*"
print(''.join(S))

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    cout << t + s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,m;
    cin >> n >> m;
    cout << (n-1)*(m-1) << endl;
}

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

int main() {
    int n;
    scanf("%d", &n);
    vector<int> x(10,0);
    vector<vector<int> > y(3,x);
    vector<vector<vector<int> > > z(4,y);
    for (int i = 0; i < n; i++) {
        int b,f,r,v;
        scanf("%d%d%d%d", &b,&f,&r,&v);
        b--; f--; r--;
        z.at(b).at(f).at(r) += v;
    }
    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                printf(" %d", z.at(i).at(j).at(k));
            }
            printf("\n");
        }
        if (i != 3) {
            printf("####################\n");
        }
    }
}


Measured memory_bytes: 3240
import sys
# input = sys.stdin.readline
sys.setrecursionlimit(pow(10, 6))

xedges = [[] for _ in range(100001)]
yedges = [[] for _ in range(100001)]
xvisited = [False for _ in range(100001)]
yvisited = [False for _ in range(100001)]

def dfs(i, xy):
  if xy == 0:
    xvisited[i] = True
  else:
    yvisited[i] = True
  xc, yc, ec = (xy+1)%2, xy%2, 0
  if xy == 0:
    ec += len(xedges[i])
    for toy in xedges[i]:
      if not yvisited[toy]:
        _xc, _yc, _ec = dfs(toy, 1)
        xc += _xc
        yc += _yc
        ec += _ec
  else :
    ec += len(yedges[i])
    for tox in yedges[i]:
      if not xvisited[tox]:
        _xc, _yc, _ec = dfs(tox, 0)
        xc += _xc
        yc += _yc
        ec += _ec
  return xc, yc, ec

def main():
  n = int(input())
  for _ in range(n):
    x, y = map(int, input().split())
    xedges[x].append(y)
    yedges[y].append(x)

  ans = 0
  for i in range(1, 100001):
    if not xvisited[i] and len(xedges[i]) != 0:
      xc, yc, ec = dfs(i, 0)
      ans += xc*yc-ec//2
    elif not yvisited[i] and len(yedges[i]) != 0:
      xc, yc, ec = dfs(i, 1)
      ans += xc*yc-ec//2

  print(ans)


if __name__ == '__main__':
  main()


Measured memory_bytes: 118316
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A, B, C;
    cin >> A >> B >> C;
    if(A.back() == B.front() && B.back() == C.front()) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 3524
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#include <time.h>
#include <ctype.h>

int cmp(const void *a, const void *b) { return *(int*)a - *(int*)b; }
int max(int a, int b) { return a >= b ? a : b; }
int min(int a, int b) { return a <= b ? a : b; }
int dsum(int x) { int r=0; while(x){ r+=(x%10); x/=10; } return r;}
void swap(int *a, int *b) { int tmp; tmp = *a; *a = *b; *b = tmp; return; }

int main(void) {
  int n;
  while(scanf("%d",&n) != EOF) {
    if(n % 39 != 0) printf("3C%02d\n",n % 39);
    else printf("3C39\n");
  }
  return 0;
}


Measured memory_bytes: 1984
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
typedef long long LL;

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

	LL N, x;
	cin >> N >>x;
	vector<LL> A;
	for(int i=0; i<N; i++){
		LL a; cin >> a;
		A.push_back(a);
	}
	sort(A.begin(), A.end());
	int ans = 0;
	for(int i=0; i<N; i++){
		if(x >= A[i] && i<N-1){
			ans++;
			x -= A[i];
		}
		else if(x == A[i] && i==N-1){
			ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 3748
#include<iostream>
typedef unsigned long long ULL;
using namespace std;

int main(){
  int A,B,i;
  cin>>A>>B;
  for(i=1;i<=1000;i++){
    if(i*8/100==A && i*10/100==B){
      cout<<i<<endl;
      return 0;
    }
  }
  cout<<"-1"<<endl;
}

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

#define rep(i, s, n) for (int i = s; i < n; ++i)
#define rrep(i, n) for (int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
typedef long long ll;
typedef pair<int, int> P;

void func(long long N, long long K) {
    cout << min(N % K, abs((N % K) - K)) << endl;
}

int main() {
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld", &N);
    long long K;
    scanf("%lld", &K);
    func(N, K);
    return 0;
}


Measured memory_bytes: 256
from itertools import product

N, *ABCs = map(int, input().split())
ls = [int(input()) for _ in range(N)]

ans = float('inf')
for ps in product(range(4), repeat=N):
    cost = 0

    lenBs = [0] * 3
    for i, p in enumerate(ps):
        if p < 3:
            if lenBs[p]:
                cost += 10
            lenBs[p] += ls[i]

    if lenBs[0]*lenBs[1]*lenBs[2] == 0:
        continue

    for ABC, lenB in zip(ABCs, lenBs):
        cost += abs(ABC - lenB)
    ans = min(ans, cost)

print(ans)


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n; cin>>n;
	int ans=1e9;
	for(int i=0;i<=n;++i){
		int tans=0,j=i,k=n-i;
		while(j>0)tans+=j%9,j/=9;
		while(k>0)tans+=k%6,k/=6;
		ans=min(ans,tans);
	}
	cout<<ans<<"\n"s;
}

Measured memory_bytes: 256
// #define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;

#define MP make_pair
#define fastIO	cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c)	for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(), c_end=c.end(); it!=c_end; ++it)

// ------------------- include, typedef, define END. -------------------

bool sosuuCheck(int n){
	if (n % 2 == 0)	return false;
	for (int i = 3;i<=sqrt((double)n);i+=2){
		if (n%i == 0)	return false;
	}
	return true;
}

int solve(int n, set<int> &sosuuList){
	int ans = 0;
	foreach_it(set<int>, it, sosuuList){
		if ((*it) > n / 2)	break;
		if (sosuuList.find(n - (*it)) != sosuuList.end())
			ans++;
	}
	/*for (int i = 3; i <= n / 2; i += 2){
		if (sosuuCheck(i)){
			if (sosuuCheck(n - i)){
				ans++;
			}
		}
	}*/
	return ans;
}

int main(){
	// 以下URLよりも速いかどうか気になったのでこのコードを書いた.
	// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=1136634#1
	fastIO;
	int n;
	set<int> sosuuList;
	sosuuList.insert(2);
	sosuuList.insert(3);
	for (int i = 5; i <= 1000000; i += 2){
		if (sosuuCheck(i))
			sosuuList.insert(i);
	}

	while (cin >> n, n){
		cout << solve(n,sosuuList) << endl;
	}
	return 0;
}

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

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> arr(n);
  for(int i=0;i<n;i++){
    cin>>arr[i];
  }
  int mindist=INT_MAX;
  for(int left=0;left<n-k+1;left++){
    int right=left+k-1;
    int leftans=abs(arr[left])+abs(arr[right]-arr[left]);
    int rightans=abs(arr[right])+abs(arr[right]-arr[left]);
    
    mindist=min(mindist,min(leftans,rightans));
  }
   cout<<mindist<<"\n";
     return 0;
}


Measured memory_bytes: 640
#include <iostream>                                                      
#include <cstdio>                                                        
using namespace std;                                                     
                                                                         
int main() {                                                             
  while (true) {                                                         
    int H, W;                                                            
    cin >> H >> W;                                                       
    if (H==0 && W==0) {                                                  
      break;                                                             
    }                                                                    
    for (int i=0; i<H; i++) {                                            
      for (int j=0; j<W; j++) {                                          
        if ((i%2==0 && j%2==0)||(i%2!=0 && j%2!=0)) {                    
          printf("#");                                                   
        } else {                                                         
          printf(".");                                                   
        }                                                                
      }                                                                  
      printf("\n");                                                      
    }                                                                    
    printf("\n");                                                        
  }                                                                      
  return 0;                                                              
}                                       

Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n); i++)
#define sz(x) int(x.size())
using namespace std;

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

    sort(d.begin(), d.end());

    cout << d[n/2]-d[(n-1)/2] << endl;

    return 0;
}


Measured memory_bytes: 640