akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define INF 1000000001
using namespace std;
typedef tuple<int, int, string> TP;

int main()
{
	int N, Q, EY,WY;
	string EN;
	while (cin >> N >> Q, N || Q) {
		vector<TP> Eras(N);
		for (int i = 0; i < N; i++) {
			cin >> EN >> EY >> WY;
			get<0>(Eras[i]) = WY - EY + 1;
			get<1>(Eras[i]) = WY;
			get<2>(Eras[i]) = EN;
		}
		sort(Eras.begin(), Eras.end());
		for (int i = 0, q; i < Q; i++) {
			cin >> q;
			auto up = upper_bound(Eras.begin(), Eras.end(), TP(q, INF, string()));
			if (up == Eras.begin() || get<0>(*(up - 1)) > q || get<1>(*(up - 1)) < q)
				cout << "Unknown" << endl;
			else
				cout << get<2>(*(up - 1)) << ' ' << (q - get<0>(*(up - 1)) + 1) << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3092
def main():
    s = input()

    for i, a in enumerate(s):
        if i % 2 == 0:
            if a == "L":
                print("No")
                break
        else:
            if a == "R":
                print("No")
                break
        if len(s) == i+1:
            print("Yes")


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include<stdio.h>
int main(void)
{
	int i,x[10+1],goukei;
	goukei=0;
	for(i=1;i<=10;i++) {
		scanf("%d",&x[i]);
		goukei+=x[i];
	}
	printf("%d\n",goukei);
	return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      Map<Integer, Integer> freq = new HashMap<>();
      for(int i = 0; i < n; i++) {
        int num = sc.nextInt();
        freq.put(num, freq.getOrDefault(num, 0) + 1);
      }
      int cnt = 0;
      for(Map.Entry<Integer, Integer> entry : freq.entrySet()) {
        int key = entry.getKey();
        int val = entry.getValue();
        if(key == val) continue;
        if(key > val) cnt += val;
        else cnt += val - key;
      }

      System.out.println(cnt);
  }
}

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

public class Main {

	static final long mod = 998244353;

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int N = sc.nextInt();
			int K = sc.nextInt();
			Pair[] pairs = new Pair[K];
			for (int i = 0; i < K; i++) {
				int from = sc.nextInt();
				int to = sc.nextInt();
				pairs[i] = new Pair(from, to);
			}
			Arrays.sort(pairs);
			int idx = K;
			long[] arr = new long[N + 1];
			long[] sum = new long[N + 1];
			arr[1] = 1;
			sum[1] = 1;
			for (int i = 2; i <= N; i++) {
				for (int j = 0; j < idx; j++) {
					if (pairs[j].x >= i) {
						continue;
					}
					int from = Math.max(0, i - pairs[j].y - 1);
					arr[i] += (sum[i - pairs[j].x] - sum[from]);
					arr[i] %= mod;
				}
				sum[i] = (sum[i - 1] + arr[i]) % mod;
			}
			System.out.println((arr[N] + mod) % mod);
		}
	}

	static class Pair implements Comparable {
		int x;
		int y;

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

		public int compareTo(Object x) {
			Pair other = (Pair) x;
			return this.x > other.x ? 1 : -1;
		}
	}
}

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

#define add push_back
#define inf 2147000000

#define rep(i,n) for(int i=0;i<n;i++)
#define deb(a) cout<<a<<endl
#define out(a) cout<<a<<endl;

using namespace std;

int main(void){
	int a;
	int cont;
	while(scanf("%d",&a)!=EOF){
		cont=0;
	rep(i,10)rep(j,10)rep(k,10)rep(l,10){
		if(i+j+k+l == a){
			cont++;
		}
	}
	cout<<cont<<endl;
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

struct comparator {
  int operator() (const pair<int, int>& l, const pair<int, int>& r) {
    return l.second < r.second;
  }
};

int main(int argc, char *argv[]) {
  // second = team's number                                                                                                                                               
  vector<pair<int, int> >team;
  int n, a, b, c, d, game;
  cin >> n;
  for (int i = 0; i < n; i++)
    team.push_back(pair<int, int>(0, i));
  game = n * (n-1) / 2;

  for (int i = 0; i < game; i++) {
    cin >> a >> b >> c >> d;
    if (c > d) {
      team[a-1].first += 3;
    } else if (c < d) {
      team[b-1].first += 3;
    } else {
      team[a-1].first++;
      team[b-1].first++;
    }
  }

  sort(team.rbegin(), team.rend());
  int points = -1, rank = 1;
  for (int i = 0; i < n; i++)
    if (team[i].first == points) {
      team[i].first = rank;
    } else {
      points = team[i].first;
      team[i].first = i+1;
      rank = i+1;
    }
  struct comparator comp;
  sort(team.begin(), team.end(), comp);

  for (int i = 0; i < n; i++)
    cout << team[i].first << endl;
  return 0;
}

Measured memory_bytes: 1204
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.List;

public class Main {

	public static void main(String[] args) {
		
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			try {
				while(true) {
					List<String> line =  Arrays.asList(br.readLine().split("\\s"));
					int a = Integer.parseInt(line.get(0)); 
					int b = Integer.parseInt(line.get(1));
					if((a==0)&&(b==0)) {
						break;
					}
					for(int i=0;i<a;i++) {
						for(int j=0;j<b;j++) {
							System.out.print("#");
						}
						System.out.print("\n");
					}
					System.out.print("\n");

				}
			}catch(IOException e) {
				e.printStackTrace();
			}
	}
}



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

int n,m;
bool graph[50][50];
bool vis[50];

void dfs(int x){
  if(vis[x]) return;
  vis[x]=true;
  for(int i=0;i<n;i++){
    if(!graph[x][i]) continue;
    dfs(i);
  }
}

int main(){
  cin>>n>>m;
  int a[m],b[m],ans=0;
  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    a[i]--;b[i]--;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  for(int i=0;i<m;i++){
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
    for(int j=0;j<n;j++) vis[j]=false;
    dfs(0);
    bool bridge=false;
    for(int j=0;j<n;j++){
      if(!vis[j]){
        bridge=true;
        break;
      }
    }if(bridge) ans++;
    graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
  }
  cout<<ans<<endl;
}

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

int main()
{
  int n, a,b;
  cin >> n >> a >> b;
  int ret = 0;
  for(int i = 1; i <=n; ++i){
    int sum = 0;
    int temp = i;
	while(temp != 0){
      sum += temp - (temp / 10) * 10;
      temp /= 10;
    }
    if(a<=sum&&sum<=b){
      ret += i;
    }
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int a[11];
int l[11];
int r[11];
int lp=0,rp=0;


int main(){
  int i,j;
  int k;
  int flag=1;
  scanf("%d",&k);
  for(j=0;j<k;j++){
  for(i=0;i<10;i++)scanf("%d",&a[i]);
  l[0]=0;
  r[0]=0;
  lp=0;
  rp=0;
  for(i=0;i<10;i++){
    if(l[lp]<a[i]){
      lp++;
      l[lp]=a[i];
    }
    else if(r[rp]<a[i]){
      rp++;
      r[rp]=a[i];
    }
    else {
      flag=0;
      break;
    }
  }
  if(flag)printf("YES\n");
  else printf("NO\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include<iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  //整数の時はint
  int a,b,c,d;
  //文字の時はstring
  // int a;

  int sum=0;
  cin>>a>>b>>c>>d;
  while(1){
     c-=b;
     if(c<=0){
       break;
     }
     a-=d;
     if(a<=0){
       break;
     }
  }
  if(c<=0)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  
  return 0;
}


Measured memory_bytes: 3624
#!/usr/bin/python2
# -*- coding: utf-8 -*-

import sys

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return map(proc, rl().split())
    else:
        return rl().split()

def main():
    a, b, x = srl(int)
    s = a / x * x
    if s < a:
        s += x
    if s > b:
        print 0
        return
    print (b - s) / x + 1


if __name__ == '__main__':
    main()


Measured memory_bytes: 2568
#include<cstdio>
#include<iostream>
#include<vector>
#include<cmath>
using namespace std;

int main(void) {
	int A, B, H, M;
	scanf("%d %d %d %d", &A, &B, &H, &M);
	const double PI = 4 * atan(1);

	double rad = 2 * PI * (H / 12. + M / 60. / 12. - M / 60.);
	// cout << beta / PI << " " << alpha / PI << endl;
	printf("%.15lf", sqrt(A*A + B*B - 2*A*B*cos(rad)));

	return 0;
}


Measured memory_bytes: 4172
#include <stdio.h>
#include "ctype.h"

int N, K;
char str[50 + 1];

int main(void)
{
  scanf("%d %d\n", &N, &K);
  scanf("%s", str);
  str[K - 1] = tolower(str[K - 1]);
  printf("%s\n", str);
  return 0;
}


Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
// -----------------<fast IO>------------------
#define IOS             ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FLSH             fflush(stdout)
#define fileIO(name) \
    freopen(name".in", "r", stdin); \
    freopen(name".out", "w", stdout);
#define PRECISION(x)     cout << fixed << setprecision(x);
// -----------------<TypeDef Start>------------------
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
// -----------------<Constants>------------------
const int MAXN = 1000005;
const int SQRTN = 1003;
const int LOGN = 22;
const double PI=acos(-1);

const int INF=1e9;

int MOD = 1000000007;
const int FMOD = 998244353;
const double eps = 1e-9;
/*ll gcd(ll a,ll b)
{
    if(a==0)
    return(b);
    return(gcd(b%a,a));
}*/
// --------------------------------------------------</TEMPLATE>--------------------------------------------------

void solve()
{
    ll n,k;
    cin>>n>>k;
    ll arr[n];
    for(ll i=0;i<n;i++)
        cin>>arr[i];
    ll dp[n];
    for(ll i=0;i<n;i++)
        dp[i]=INT_MAX;
    dp[0]=0;
    for(ll i=1;i<n;i++)
    {
        if(i<=k)
        {
            for(ll j=0;j<=i;j++)
            {
                dp[i]=min(dp[i],dp[j]+abs(arr[i]-arr[j]));
            }
        }
        else
        {
            for(ll j=1;j<=k;j++)
            {
                dp[i]=min(dp[i],dp[i-j]+abs(arr[i]-arr[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<endl;
}

int main()
{
    IOS
    ll t=1;
   // cin>>t;
    while(t--)
    {
        solve();
    }
    return(0);
}


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

int main(void)
{

    char n[200000];
    int i, j;

    cin >> n;

    j = 0;
    for(i=0;i<200000;i++){
        if(n[i] == '\0'){
            break;
        }
        j += n[i] - '0';
    }

    if(j % 9 == 0){
        cout << "Yes";
    }else{
        cout << "No";
    }


    return 0;



}

Measured memory_bytes: 3692
#include <cstdio>
int main(){
    int a,b; char op;
    for(;;){
        scanf("%d %c %d",&a,&op,&b);
        if(op=='?')break;
        if(op=='+')printf("%d\n",a+b);
        if(op=='-')printf("%d\n",a-b);
        if(op=='*')printf("%d\n",a*b);
        if(op=='/')printf("%d\n",a/b);
    }
    return 0;
}



Measured memory_bytes: 2608
/********************    I am only one, but still I am one.    **************************************/
/**************    I cannot do everything, but still I can do something.    *************************/
/***   And because I cannot do everything I will not refuse to do the something that I can do.    ***/
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;

const int maxn = 200, maxm = 1e5, mod = 1e9+7;
int dp[maxn+1][maxm+1];
vector<int>a;
int n,x;

int solve(int i,int x){
	if( i == n ) return x;
	int & ans = dp[i][x];
	if( ans != -1 )return ans;
	ans = 0;
	ans += solve(i+1,x%a[i]) + solve(i+1,x) * (n - i - 1) % mod;
	// a[i] comes at ith place => x%a[i]
	// a[i] comes rest of ( n - i - 1 ) place => no change
	ans %= mod;
	return ans;
}
int32_t main(){
	IOS
	cin >> n >> x;
	a = vector<int>(n);
	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	sort(a.rbegin(),a.rend());
	memset(dp,-1,sizeof(dp));
	cout << solve(0,x);
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


Measured memory_bytes: 160716
"use strict";
function Main(input) {
    let cin = new Inputer(input);
    let N = cin.getInt();
    let A = cin.getIntArray(N);
    const gcd = (a, b) => {
        return b ? gcd(b, a % b) : a;
    }
    let L = new Array(N+1); L[0] = 0;
    let R = new Array(N+1); R[N] = 0;
    for (let n = 0; n <= N; n++) {
        L[n+1] = gcd(L[n], A[n]);
    }
    for (let n = N-1; n >= 0; n--) {
        R[n] = gcd(R[n+1], A[n]);
    }
    let M = new Array(N);
    for (let n = 0; n < N; n++) {
        M[n] = gcd(L[n], R[n+1]);
    }
    console.log(Math.max(...M));
}
class Inputer{constructor(t){if(typeof t=='undefined')throw new Error('引数（stdin）を省略できません！');this.cnt=0,this.items=t.split(/\n|\s/)}getInt(){return this.items[this.cnt++]-0}getIntArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getInt();return r}getStr(){return this.items[this.cnt++]}getStrArray(t){if(typeof t=='undefined')throw new Error('引数（1以上）を省略できません！');let r=new Array(t);for(let e=0;e<t;e++)r[e]=this.getStr();return r}}
if (typeof window == "undefined") Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 49460
//#define anjn
//      Anjan Agarwala - anjn98

//#define opti
#ifdef opti
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#endif

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, 
                  tree_order_statistics_node_update> ordered_set;

ll power(ll x,ll y,ll p){ll r=1; x=x%p; while(y){ if(y&1) r= r*x%p; y=y>>1; x=x*x%p; } return r; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int csrand(int l=0, int r=1e9){
  uniform_int_distribution<int> uid(l, r);
  return uid(rng);
}

#define PR(x) cout<<#x<<": "<<x<<"\n";
#define PR1(x,y) cout<<#x<<": "<<x<<"  |  "<<#y<<": "<<y<<"\n";
#define PR2(x,y,z) cout<<#x<<": "<<x<<"  |  "<<#y<<": "<<y<<"  |  "<<#z<<": "<<z<<"\n";
#define ED cout<<'\n';

#define IO              ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FILEIO          freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define all(v)          v.begin(),v.end()
#define endl            '\n'
#define fr1(j,n)        for(int j=0;j<n;j++)
#define fr(n)           for(int i=0;i<n;i++)
#define trav(x,s)       for(auto x:s)
#define PB              push_back
#define pii             pair<int,int>
#define pll             pair<long long int,long long int>
#define F               first
#define S               second 
#define binf            2000000000000000001
#define mod             1000000007


const int N=1e6+99;
ll val[N];

bool comp(pair<string,int> a,pair<string,int> b)
{
	if(a.F==b.F)
		return val[a.S-1] > val[b.S-1];	
	return a.F < b.F;
}

int32_t main() 
{



    int n ;
    cin>>n;
    vector<pair<string,int>> v(n);

    fr(n)
    	cin>>v[i].F>>val[i], v[i].S=i+1;

    sort(all(v),comp);

    fr(n)
    	cout<<v[i].S<<endl;



     
}



Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;


int main() {
	int N;
	cin >> N;
	vector<int> Ns;
	Ns.resize(N);
	int Max = 0;
	int Index = 0;
	for (int i = 0; i < N; i++) {
		cin >> Ns[i];
		if (Max < Ns[i]) {
			Max = Ns[i];
			Index = i;
		}
	}
	int Mid = Max;
	int R = 0;
	for (int i = 0; i < N; i++) {
		if (Index == i)continue;
		if (Mid > abs(Max / 2 - Ns[i])) {
			R = Ns[i];
			Mid = abs(Max / 2 - Ns[i]);
		}
	}
	cout << Max << " " << R << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
	int x[4] = {}, y[4] = {};
	scanf("%d %d %d %d", &x[0], &y[0], &x[1], &y[1]);

	x[2] = x[1] + y[0] - y[1];
	y[2] = y[1] + x[1] - x[0];
	x[3] = x[0] + y[0] - y[1];
	y[3] = y[0] + x[1] - x[0];

	printf("%d %d %d %d", x[2], y[2], x[3], y[3]);
	return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

ll a,b,c,d,n;
priority_queue<ll,vector<ll>,greater<ll> > p1,p2;
ll ans=0;

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

	cin>>a>>b>>c>>d>>n;
	p1.push(4*a);p1.push(2*b);p1.push(c);
	p2.push(8*a);p2.push(4*b);p2.push(2*c);p2.push(d);
	if(n>=2) {
		ll x=p2.top();
		ll num=n/2;
		if(n%2==1) n=1;
		ans+=num*x;
	}
	if(n==1) {
		ans+=p1.top();
	}
	cout<<ans<<endl;

	return 0;
}


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

using namespace std;
int A[10][10];
int N;
const int W = 10;
const int H = 10;
const int L = 13;

pair<int, int> next() {
    REP(y, H) REP(x, W) if(A[y][x] > 0) {
        return make_pair(x, y);
    }
    return make_pair(-1, -1);
}
int len[4] = {0, 5, 9, 13};
int dx[] = {
    0, 1, 0, -1, 0,  1, 1, -1, -1,  2, 0, -2, 0
};
int dy[] = {
    0, 0, 1, 0, -1,  1, -1, -1, 1,  0, 2, 0, -2
};
int r[3] = {1, 1, 2};

int ok(int cx, int cy) {
    REP(i, L) {
        int x = cx + dx[i];
        int y = cy + dy[i];
        if(x < 0 || W <= x) return i;
        if(y < 0 || H <= y) return i;
        if(A[y][x] == 0) return i;
    }
    return L;
}
void add(int cx, int cy, int l, int r, int d) {
    for(int i = l; i < r; i++) {
        int x = cx + dx[i];
        int y = cy + dy[i];
        A[y][x] += d;
    }
}

int hist_x[15];
int hist_y[15];
int hist_z[15];

bool dfs(int iter) {
    if(iter == N) {
        if(next().first != -1) return false;
        REP(i, N) {
            int x = hist_x[i];
            int y = hist_y[i];
            int z = hist_z[i];
            cout << x << " " << y << " " << z << endl;
        }
        return true;
    }

    auto p = next();
    int px = p.first, py = p.second;
    // REP(y, H) {
    //     REP(x, W) cout << A[y][x] << " ";
    //     cout << endl;
    // }
    REP(k, 3) for(int i = len[k]; i < len[k + 1]; i++) {
        int cx = px - dx[i];
        int cy = py - dy[i];
        int r = ok(cx, cy);

        int last = 0;
        for(int k2 = k; k2 < 3; k2++) {
            if(len[k2 + 1] <= r) {
                add(cx, cy, len[last], len[k2 + 1], -1);
                hist_x[iter] = cx;
                hist_y[iter] = cy;
                hist_z[iter] = k2 + 1;
                if(dfs(iter + 1)) return true;
                last = k2 + 1;
            } else {
                break;
            }
        }

        if(last > 0) {
            add(cx, cy, len[0], len[last], +1);
        }
    }

    return false;
}



int main(){
    while(cin >> N) {
        REP(y, H) REP(x, W) cin >> A[y][x];

        bool b = dfs(0);
        assert(b);
    }
    return 0;
}

Measured memory_bytes: 1164
n,m,k = map(int,input().split())
import sys
rks = [None] *n
sys.setrecursionlimit(10**9)
fgraph = [list() for i in range(n)]
bgraph = [list() for i in range(n)]
cgraph = [list() for i in range(n)]
g = [[]for i in range(n)]
for i in range(m):
        a,b = map(int, input().split())
        fgraph[a-1].append(b)
        fgraph[b-1].append(a)
def dfs(graph,s,r):
    if rks[s] is None:
        rks[s] = r
    for i in range(len(graph[s])):
        if rks[graph[s][i]-1] is not None:
            continue
        g[r].append(0)
        dfs(graph, graph[s][i]-1,r)
c = -1
for i in range(n):
    if rks[i] is None:
        c += 1
        dfs(fgraph, i, c)
for i in range(k):
        c,d = map(int, input().split())
        if rks[c-1] == rks[d-1]:
            bgraph[d-1].append(c)
            bgraph[c-1].append(d)
for i in range(n):
        print(len(g[rks[i]]) - len(fgraph[i]) - len(bgraph[i]) )

Measured memory_bytes: 67568
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#pragma endregion

template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}

bool chmax(ll &a, ll b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);

  int n;
  cin >> n;
  ll a[200010];
  rep(i, n) cin >> a[i];
  if (n == 2)
    a[2] = -LINF;
  ll dp[200010][3];
  Fill(dp, -LINF);
  dp[1][0] = a[0];
  dp[2][1] = a[1];
  dp[3][2] = a[2];
  rep(i, n + 1)
  {
    if (i >= 2)
    {
      chmax(dp[i][0], dp[i - 2][0] + a[i - 1]);
      chmax(dp[i][1], dp[i - 2][1] + a[i - 1]);
      chmax(dp[i][2], dp[i - 2][2] + a[i - 1]);
    }
    if (i >= 3)
    {
      chmax(dp[i][1], dp[i - 3][0] + a[i - 1]);
      chmax(dp[i][2], dp[i - 3][1] + a[i - 1]);
    }
  }
  ll Max = -LINF;
  if (n % 2 == 0)
  {
    chmax(Max, dp[n - 1][0]);
    chmax(Max, dp[n][1]);
  }
  else
  {
    chmax(Max, dp[n - 2][0]);
    chmax(Max, dp[n - 1][1]);
    chmax(Max, dp[n][2]);
  }
  cout << Max << endl;
  return 0;
}


Measured memory_bytes: 9808
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
const ll MAX = 3001;
ll dp[2][MAX][MAX];

int main(void)
{
	ll n;
	cin >> n;
	ll a[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];

	for(int i = 0; i < n; i++)
	{
		dp[0][i][i] = a[i];
		dp[1][i][i] = 0;
	}

	for(int l = 2; l <= n; l++)
	{
		for(int i = 0; l + i <= n; i++)
		{
			int j = l + i - 1;
			dp[0][i][j] = max(a[i] + dp[1][i + 1][j], a[j] + dp[1][i][j - 1]);
			
			if(dp[0][i][j] == a[i] + dp[1][i + 1][j])
				dp[1][i][j] = dp[0][i + 1][j];
			else
				dp[1][i][j] = dp[0][i][j - 1];
		}
	}
	
	cout << dp[0][0][n - 1] - dp[1][0][n - 1] << endl;





	return 0;
}

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

int main()
{
    int n;
    cin >> n ;
    string s;
    cin >> s;
    int ans = 0;
    rep(i,n){
        if(s[i] != s[i + 1]){
            ans ++;
        }
    }
    if(ans == 0){
        ans ++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 512
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
#define min(x,y) (x < y ? x : y)
#define max(x,y) (x < y ? y : x)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll n, h, w; cin >> n >> h >> w;
  cout << (n-h+1) * (n-w+1) << endl;
}


Measured memory_bytes: 256
input_list = []
while True:
    pair = list(map(int, input().split(' ')))
    if pair[0] == 0 and pair[1] == 0:
        break
    input_list.append(pair)

for pair in input_list:
    h = pair[0]
    w = pair[1]
    start_mark = '#'
    m = start_mark
    for y in range(h):
        for x in range(w):
            print(m, end='')
            if m == '#':
                m = '.'
            else:
                m = '#'
        print()
        if start_mark == '#':
            m = '.'
            start_mark = m
        else:
            m = '#'
            start_mark = m
    print()




Measured memory_bytes: 7004
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(x => Number(x));
  const a = s[0];
  const b = s[1];
  const k = s[2];
  let ans = new Set();

  for (let i = 0; i < k; i++) {
    if ((a + i) <= b || (b - i) >= a) {
      ans.add(a + i);
      ans.add(b - i);
    } else {
      break;
    }
  }

  ans = [...ans].sort((a, b) => a - b).join('\n')
  console.log(ans);
}

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


Measured memory_bytes: 9672
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;

int main() {
    // 頂点数と辺数、s と t
    int N, M; cin >> N >> M;

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    int k[N];

    // 頂点 s をスタートとした探索
    vector<int> dist(N, -1);
    queue<int> que;
    dist[0] = 0, que.push(0);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (dist[nv] == -1) {
                dist[nv] = dist[v] + 1;
                que.push(nv);
                k[nv]=v;
            }
        }
    }
  cout<<"Yes"<<endl;

    for(int i=1;i<N;i++){
      cout<<k[i]+1<<endl;
    }
}

Measured memory_bytes: 10664
#include <stdio.h>
#include <iostream>

using namespace std;

int main()
{long long a,b,x,z,w;
cin>>a>>b>>x;
z=b/x;
if (a==0)
    cout << z+1;
else
{
    w=(a-1)/x;
    cout <<z-w;


}

   return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import bisect
import copy

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 16
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().split()))


# ===CODE===


def main():
    n = ni()
    yes = dict()
    for i in range(3, 1000):
        if (i * (i - 1)) % 2 == 0:
            yes[(i * (i - 1)) // 2] = [i, i - 1]
    tmp = max(yes)

    if n == 1:
        print("Yes")
        print(2)
        print(1, 1)
        print(1, 1)
        exit(0)


    if n not in yes.keys():
        print("No")
        exit(0)

    xl, xs = yes[n]

    ans = [[] for _ in range(xl)]
    cnt = 1
    idx = 0
    while xs >= 1:
        tmp = cnt
        for i in range(idx, min(xl, idx + 3)):
            for j in range(xs):
                if cnt == tmp + 3 * (xs - 1):
                    ans[i].append(tmp)
                    break
                else:
                    ans[i].append(cnt)
                if j != 0 and j != xs - 1:
                    ans[idx + 2 + j].append(cnt)
                if j != xs - 1:
                    cnt += 1
        idx += 3
        xs -= 3

    print("Yes")
    print(len(ans))
    for ansi in ans:
        print(len(ansi), *ansi, sep=" ")


if __name__ == '__main__':
    main()


Measured memory_bytes: 14904
#a = gets.split(" ").map{|x| x.to_i}
=begin
n = gets.to_i
count = 0
n.times do |i|
  if((i + 1) % 2 == 1)
    count += 1
  end
end
p count.to_f / n.to_f
=end

nk = gets.split(" ").map{|x| x.to_i}
N = nk[0]
K = nk[1]

h = gets.split(" ").map{|x| x.to_i}
count = 0

N.times do |i|
  if(K <= h[i])
    count += 1
  end
end
p count


Measured memory_bytes: 7940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
#define int long long

signed main() {
  int N, K; cin >> N >> K;
  vector<int> x(N), y(N);
  vector<int> xary, yary;

  for(int i = 0; i < N; ++i) {
    cin >> x[i] >> y[i];
    xary.push_back(x[i]);
    yary.push_back(y[i]);
  }
  sort(xary.begin(), xary.end());
  sort(yary.begin(), yary.end());

  int ans = 1LL * (xary[N-1] - xary[0]) * (yary[N-1] - yary[0]);

  for(int xi = 0; xi < N; ++xi) {
    for(int xj = xi + 1; xj < N; ++xj) {
      for(int yi = 0; yi < N; ++yi) {
        for(int yj = yi + 1; yj < N; ++yj) {
          int num = 0LL;
          int lx = xary[xi], rx = xary[xj];
          int by = yary[yi], uy = yary[yj];

          for(int i = 0; i < N; ++i) {
            if(lx <= x[i] && x[i] <= rx && by <= y[i] && y[i] <= uy) {
              num++;
            }
          }
          if(num >= K) ans = min(ans, 1LL * (rx - lx) * (uy - by));
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > v;
int dp[100001];
int dfs(int i)
{
    if(dp[i]!=1)return dp[i];
    else 
    {for(int j=0;j<v[i].size();j++)
    {
        dp[i]=max(dp[i],1+dfs(v[i][j]));
    }
       return dp[i]; 
    }
}
int main()
{
    int n,m;
    cin>>n>>m;
    v.resize(n+1);
    for(int i=0;i<=100001;i++)dp[i]=1;
for(int i=0;i<m;i++)
{
    int x,y;
    cin>>x>>y;
    v[x].push_back(y);
}
int ans=-1;
for(int i=0;i<n;i++)
{
    ans=max(ans,dfs(i+1));
}
cout<<ans-1;
}

Measured memory_bytes: 10964
import java.util.*;
import java.lang.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		if(a==b)System.out.println(c);
		else if(a==c)System.out.println(b);
		else System.out.println(a);
	}
}

Measured memory_bytes: 21972
#include<cstdio>
#include<cmath>
using namespace std;

int n, a, b, c, d;
double A, B, C, E = 1e-10;

double f(double x) {
  return a * x * x * x + b * x * x + c * x + d;
}

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    int M = 0, P = 0;
    scanf("%d%d%d%d", &a, &b, &c, &d);
    if (d != 0) {
      double minas = 1000.0, plus = -1000.0;
      if (f(minas) > 0.0) minas = -1000.0, plus = 1000.0;
      double mid = 0.0;
      while (abs(f(mid)) > E) {
        if (f(mid) < E) minas = mid;
        else plus = mid;
        mid = (minas + plus) / 2.0;
      }
      if (mid > E) P++;
      else if (mid < -E) M++;
      A = (double)a, B = (double)b + mid * A, C = (double)c + mid * B;
    } else {
      A = (double)a, B = (double)b, C = (double)c;
    }
    double D = B * B - 4 * A * C;
    if (D > E) {
      double d2 = sqrt(D);
      if (A*(d2 - B) > E) P++;
      if (A*(d2 - B) < -E) M++;
      if (A*(-d2 - B) > E) P++;
      if (A*(-d2 - B) < -E) M++;
    } else if (D > -1e-4) {
      if (A*(-B) > E) P += 2;
      if (A*(-B) < -E) M += 2;
    }
    printf("%d %d\n", P, M);
  }
}



Measured memory_bytes: 2588
fun main(args: Array<String>) {
    Program().solve()
}

class Program {
    fun solve() {
        val sc = MyScanner()
        val a = sc.nextInt()
        val b = sc.nextInt()
        println((b - 1 + a - 2) / (a - 1))
    }
}


class MyScanner() {
    private var index = 0
    private var line = listOf<String>()

    fun next(): String {
        while (line.size <= index) {
            line = readLine()!!.split(' ')
            index = 0
        }
        return line[index++]
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextDouble() = next().toDouble()
    fun nextCharArray() = next().toCharArray()
    fun nextChar() = next()[0]

    fun strList(): List<String> {
        index = line.size
        return readLine()!!.split(' ')
    }

    fun intList() = strList().map { it.toInt() }
    fun longList() = strList().map { it.toLong() }
    fun doubleList() = strList().map { it.toDouble() }
}

Measured memory_bytes: 38208
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int stringCount = sc.nextInt();
    int stringLength = sc.nextInt();
    String blank = sc.nextLine();
    String[] array = new String[stringCount];
    for(int i = 0; i < stringCount;i++){
      array[i] = sc.nextLine();
    }
    
	Arrays.sort(array);
    String result = "";
    for(String val : array){
      result += val;
    }
    
    System.out.println(result);
  }
}

Measured memory_bytes: 25428
# https://atcoder.jp/contests/abc127/tasks/abc127_e

import itertools
from collections import Counter
from collections import defaultdict
import bisect
import math

# Calculate count of combination
def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result


def combination(n, r):
    if r == 0:
        return 1
    a = 1
    b = 1
    for i in range(r):
        a *= (n - i)
        if a % (i + 1):
            a //= (i + 1)
        else:
            b *= (i + 1)
    return a // b


def main():
    MOD = 10**9 + 7
    N, M, K = map(int, input().split())

    pattern = cmb(N * M - 2, K - 2)
    # print(com)
    pattern = pattern % MOD
    # print(com)

    ans = 0

    for dx in range(1, M):
        ans += dx * (M - dx) * pattern * (N * N)
        ans = ans % MOD

    # y
    for dy in range(1, N):
        ans += dy * (N - dy) * pattern * (M * M)
        ans = ans % MOD

    ans = ans % MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52788
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pf push_front
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define SIZE 200010
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%d",&t)
#define p(t) printf("%d\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define print(x) for(auto el: x) cout<<el<<" ";cout<<endl
#define bits(x) __builtin_popcount(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<int,vector<int>,greater<int> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define mitr map<int,int>:: iterator


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
    fast;
    int x,a;cin>>x>>a;
    if(x<a)
        cout<<0;
    else
        cout<<10;
}

Measured memory_bytes: 256
#include<iostream>
#include <vector> 
#include <algorithm>
#include<iomanip>
#include<math.h>
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
using namespace std;

int main() {
    char szBuf[4];
    cin >> szBuf;
    if (szBuf[1] == 'B') {
        cout << "ARC" << endl;
    }
    else {
        cout << "ABC" << endl;
    }
    return 0;
}

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

int main() {
  int n;
  cin>>n;
  int vec[n-1];
  int ans[n];
  for(int i=0;i<n+1;i++){
    ans[i]=0;
  }
  for(int i=0;i<n-1;i++){
    cin>>vec[i];
    ans[vec[i]-1]++;
  }
  for(int i=0;i<n;i++){
    cout<<ans[i]<<endl;
  }
}

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

int main()
{
  	string s;
  	cin >> s;
  	string t;
  	cin >> t;
  	int minCount = 1000;
  
  	REP(i, s.length()){
      int count = 0;
      	if(s.length() < i+t.length()){
          break;
        }
      	REP(j, t.length()){
          	if(s[i+j] != t[j]){
              ++count;
            }
        }
      if(minCount > count){
        minCount = count;
      }
    }
  
  cout << minCount;
    return 0;
}

Measured memory_bytes: 3624
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<vector>
#include<queue>
#include<cmath>

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n-1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(a, n) sort(a, a+n)
#define VSORT(v) sort(v.begin(), v.end())

using namespace std;

int gcd(int p, int q);

int main()
{
    int k;

    cin >> k;

    int sum = 0;

    FOR(i, 1, k+1) {
        FOR(j, 1, k+1) {
            FOR(l, 1, k+1) {
                sum += gcd(gcd(i, j), l);
            }
        }
    }

    cout << sum << endl;

    return 0;
}

int gcd(int p, int q) {
    if(p % q == 0) { return q; }
    else { return gcd(q, p % q); }
}

Measured memory_bytes: 3648
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>

using namespace std;

int n;
const int maxn = 105;
int s[maxn];

int main(){
    cin >> n;
    int sum = 0;
    for(int i = 1;i <= n;i++){
        scanf("%d", &s[i]);
        sum += s[i];
    }
    int ans = 0;
    if(sum % 10)
        ans = sum;
    for(int i = 1;i <= n;i++){
        if((sum - s[i]) % 10){
            ans = max(ans, sum - s[i]);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back


string solve(string s){
    string ret="";
    
    int c=1;
    for(int i=1;i<s.size();i++){
        if(s[i-1]==s[i]){
            c++;
        }
        else{
            stringstream x;
            x<<c;
            ret+=x.str();
            ret+=s[i-1];
            c=1;
        }
    }
    stringstream x;
    x<<c;
    ret+=x.str();
    ret+=s[s.size()-1];
    
    return ret;
}

int main() {
    int n;
    
    while(cin>>n){
        if(n==0)break;
        
        string s;
        cin>>s;
        rep(i,n){
            s=solve(s);
        }
        cout<<s<<endl;
    }
    return 0;
}

Measured memory_bytes: 1364
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
 
bool c1[20005],c2[20005],dp[10005][20005];
int a[10005] ;
 
int main(){
	int x,y,i,j,k=0,l=0;
	string t;
	
	cin>>t;
	cin>>x>>y;
	
	for(i=0;i<t.size();i++){
		if(t[i]=='F'){
			a[k]++;
			l++;
		}
		else{
			k++;
		}
	}
	
	x=x-a[0];
	
	dp[0][8000]=true;
	dp[1][8000]=true;
	
	for(i=2;i<=k+1;i+=2){
		for(j=0;j<=16000;j++){
			if(j-a[i-1]>=0){
				dp[i][j]=dp[i][j] || dp[i-2][j-a[i-1]];
			}
			if(j+a[i-1]<=16000){
				dp[i][j]=dp[i][j] || dp[i-2][j+a[i-1]];
			}
		}
	}
	
	for(i=3;i<=k+1;i+=2){
		for(j=0;j<=16000;j++){
			if(j-a[i-1]>=0){
				dp[i][j]=dp[i][j] || dp[i-2][j-a[i-1]];
			}
			if(j+a[i-1]<=16000){
				dp[i][j]=dp[i][j] || dp[i-2][j+a[i-1]];
			}
		}
	}
	
	if(k%2==1){
		if(dp[k+1][8000+y] && dp[k][8000+x])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	else{
		if(dp[k][8000+y] && dp[k+1][8000+x])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	
	return 0;
} 

Measured memory_bytes: 155776
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
const int MOD = 1000000007;

int main() {
  string s;
  cin >> s;
  sort(s.begin(),s.end());
  if(s[0] == s[1] && s[2] == s[3] && s[1] != s[2]) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
from collections import defaultdict


def cmb(n, r):
    if n < r:
        return 0
    a = 1
    for i in range(n, n - r, -1):
        a *= i
    b = 1
    for i in range(1, r + 1):
        b *= i
    return int(a / b)


N = int(input())
AList = [int(i) for i in input().split()]

aDict = defaultdict(int)
for a in AList:
    aDict[a] += 1

ans = 0
for key in aDict:
    ans += cmb(aDict[key], 2)

for a in AList:
    print(ans - aDict[a] + 1)


Measured memory_bytes: 26772
#include <stdio.h>

int main()
{
	int i = 0;
	long int k;
	char s[101];
	scanf("%s", s);
	scanf("%ld", &k);

	while (1) {
		if (s[i] == '1' && i+1 != k) {
			i++;
			continue;
		}
		else {
			break;
		}
	}

	printf("%c\n", s[i]);

	return 0;
}

Measured memory_bytes: 128
//﻿#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:256000000")

#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
#include <set>
#include <array>
#include <unordered_set>
#include <deque>
#include <queue>
#include <iomanip>
#include <fstream>
#include <string>
#include <climits>
#include <sstream>

typedef long long ll;
typedef long double ld;

#define vi vector<int>
#define pii pair<int, int>
#define fi(n) for(int i = 0; i < (n); i++)
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define RFOR(i, k, n) for(int i = (k); i >= (n); i--)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define umin(a, b) a = min(a, b)
#define umax(a, b) a = max(a, b)

const int INF = INT_MAX;
const int mod = 1e9 + 7;
const long long LINF = LLONG_MAX;

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> v(n);
	fi(n)
		cin >> v[i];
	sort(all(v));
	int answ = 0;
	int k = 0;
	v.push_back(INF);
	while (k < n)
	{
		auto it = upper_bound(all(v), v[k] + 2);
		umax(answ, (int)(it - v.begin() - k));
		k = upper_bound(all(v), v[k]) - v.begin();
	}
	cout << answ << endl;
	return 0;
}

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

int main(){
    
    int N,A,B;
    cin >> N >> A >> B;
    string S;
    cin >> S;
    int ans = 0;
    int bns = 0;
    for(int i = 0; i < N;i++){
        
        if(S[i]=='a'&&ans<A+B){
            ans++;cout << "Yes"<<endl;
        }else if(S[i]=='b' && bns<B && ans<A+B){
            ans++;bns++;cout <<"Yes"<<endl;
        }else{
            cout <<"No"<<endl;
        }
    }
    
    
}
    
    



Measured memory_bytes: 896
import sys
sys.setrecursionlimit(200000)
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]
MEMO = [-1 for _ in range(N+1)]

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


def dp_LP(v):# 頂点nから始まる最長経路を返す.
  if MEMO[v] != -1:
    return MEMO[v]
  else:
    ans = 0
    for i in G[v]:
      ans = max(ans, dp_LP(i)+1)
    MEMO[v] = ans

    return ans



answer = 0
for n in range(1,N+1):
  answer = max(answer, dp_LP(n))
print(answer)




Measured memory_bytes: 59060
#include <bits/stdc++.h>
#define MAXN 100000

using namespace std;

pair <int, int> vx[MAXN + 1];
pair <int, int> vy[MAXN + 1];

struct Edge {
    int x;
    int y;
    int cost;
    bool operator <(const Edge &other) const{
         return cost < other.cost;
    }
}g[MAXN * 2 + 1];

int sef[2 * MAXN + 1];

int myfind(int nod) {
     if(sef[nod] == 0)
        return nod;
     return sef[nod] = myfind(sef[nod]);
}

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i,n;
    long long x,y;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> x >> y;
        vx[i].first = x;
        vx[i].second = i;
        vy[i].first = y;
        vy[i].second = i;
    }
    sort(vx + 1, vx + n + 1);
    sort(vy + 1, vy + n + 1);
    int sz = 0;
    for(i = 1; i < n; i++)
        g[++sz] = {vx[i].second, vx[i + 1].second, vx[i + 1].first - vx[i].first};
    for(i = 1; i < n; i++)
        g[++sz] = {vy[i].second, vy[i + 1].second, vy[i + 1].first - vy[i].first};
    sort(g + 1, g + sz + 1);
    long long ans = 0;
    for(i = 1; i <= sz; i++)
        if(myfind(g[i].x) != myfind(g[i].y)) {
            sef[myfind(g[i].x)] = myfind(g[i].y);
            ans += g[i].cost;
        }
    cout << ans << endl;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 4608