akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#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 revrep(i, s) for (int i = s-1; i > 0; i--)
#define revrrep(i, s) for (int i = s-1; i >= 0; i--)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

bool is_good(string S)
{
    char before = S[0];
    rep (i, 1, S.size()) {
        if (before == S[i]) return false;
        before = S[i];
    }
    return true;
}

int main()
{
    string S; cin >> S;
    if (is_good(S)) cout << "Good" << endl;
    else cout << "Bad" << endl;
}

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


int main()
{
	int a[3] ,n;
	vector<bool> dst;
	cin >> n;
	while (n-- > 0) {
		cin >> a[0] >> a[1] >> a[2];
		sort(a, a + 3);
		dst.push_back(a[0]*a[0] + a[1]*a[1] == a[2] * a[2]);
	}
	for (vector<bool>::iterator it = dst.begin(); it < dst.end(); it++)
		cout << ((*it)?"YES":"NO") << endl;
	return 0;
}


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

using ll = long long;
#define ld long double
#define ull unsigned long long int

#define rep(i, n) for (int i = 0; i < (int)(n); i++)  // (i, 10) i=0～i=9まで
#define repr(i, n) for (int i = n; i >= 0; i--)   // (i, 10) i=10～i=0まで
#define FOR(i, m, n) for (int i = m; i < n; i++)  // (i, 3, 10) i=3～i=9まで
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define ret return

typedef pair<int, int>    pii;
typedef vector<int>       vi;
typedef vector<vi>        vii;
typedef vector<long long> vl;

// 総数を1000000007で割った余り
const long long mod = 1e9 + 7;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

    // 入力
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    // 処理
    int tmp = 0;
    int ans = 0;

    tmp = max({a, b, c});
    ans = (a + b + c - tmp) + tmp * pow(2, k);

    // 出力
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<ll>>;
using P = pair<int,int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define MOD 1000000007
#define INF 1000000
#define PI 3.14159265358979323846264338327950L
#define MAX_N 200010
#define lb lower_bound //[2,4)=lb(4)-lb(2)

int main()
{
  int K;cin>>K;
  
  ll b[100040];
  queue<ll> q;
  ll count=1;
  for (ll i=1;i<=9;i++)
  {
    q.push(i);
    b[count]=i;
    count++;
  }
  
  while (!q.empty())
  {
    ll v = q.front();
    q.pop();
    for (ll i=-1;i<=1;i++)
    {
      ll nv = 10*v + (v%10+i);
      //cout<<nv<<endl;
      if (v%10+i>=0 && v%10+i<=9)
      {
        q.push(nv);
        b[count]=nv;
        count++;
      } 
    }
    if (count>K+1) break;
  }
  cout<<b[K]<<endl;
}

Measured memory_bytes: 4928
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;

#define BIG_NUM 2000000000

using namespace std;

int main(){

	char buf[5001],work[5001],pre,to_change;
	scanf("%s",buf);

	int length,limit,index,pre_length;
	bool FLG = true,A_FLG,B_FLG,C_FLG;

	for(length = 0; buf[length] != '\0'; length++);

	do{
		if(length <= 3)break;
		pre_length = length;

		limit = length-3;
		index = 0;
		pre = 'D';
		to_change = 'D';
		A_FLG = B_FLG = C_FLG = false;
		for(int i = 0; i < length;){
			if(i <= limit && buf[i] == 'A' && buf[i+1] == 'B' && buf[i+2] == 'C'){
				if(to_change == 'D'){
					switch(pre){
					case 'D':
						if(!A_FLG){
							work[index++] = 'A';
							to_change = 'A';
						}else{
							FLG = false;
						}
						break;
					case 'A':
						if(!B_FLG){
							work[index++] = 'B';
							to_change = 'B';
						}else{
							FLG = false;
						}
						break;
					case 'B':
						if(!C_FLG){
							work[index++] = 'C';
							to_change = 'C';
						}else{
							FLG = false;
						}
						break;
					case 'C':
						FLG = false;
						break;
					}
				}else{
					work[index++] = to_change;
				}
				if(!FLG)break;

				i+=3;
			}else{
				if(buf[i] == to_change){
					FLG = false;
					break;
				}else{
					work[index++] = buf[i];
					switch(buf[i]){
					case 'A':
						A_FLG = true;
						break;
					case 'B':
						B_FLG = true;
						break;
					case 'C':
						C_FLG = true;
						break;
					}

					pre = buf[i];
					i++;
				}
			}
		}
		if(!FLG){
			length = 0;
			break;
		}

		work[index] = '\0';
		length = index;

		for(int i = 0; i <= length; i++){
			buf[i] = work[i];
		}

	}while(pre_length > length);

	if(length == 3 && buf[0] == 'A' && buf[1] == 'B' && buf[2] == 'C'){
		printf("Yes\n");
	}else{
		printf("No\n");
	}

	return 0;
}

Measured memory_bytes: 2696
#define _USE_MATH_DEFINES
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <clocale>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i, s, n) for(int i = (s), i##_len=(n); i < i##_len; ++i)
#define FORS(i, s, n) for(int i = (s), i##_len=(n); i <= i##_len; ++i)
#define VFOR(i, s, n) for(int i = (s); i < (n); ++i)
#define VFORS(i, s, n) for(int i = (s); i <= (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) FORS(i, 0, n)
#define VREP(i, n) VFOR(i, 0, n)
#define VREPS(i, n) VFORS(i, 0, n)
#define RFOR(i, s, n) for(int i = (s), i##_len=(n); i >= i##_len; --i)
#define RFORS(i, s, n) for(int i = (s), i##_len=(n); i > i##_len; --i)
#define RREP(i, n) RFOR(i, n, 0)
#define RREPS(i, n) RFORS(i, n, 0)
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v), greater<decltype(v[0])>())
#define SZ(x) ((int)(x).size())
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define MT make_tuple
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(ALL(v)), v.end())

using ll = long long;
using ull = unsigned long long;
using Pi_i = pair<int, int>;
using VB = vector<bool>;
using VC = vector<char>;
using VD = vector<double>;
using VI = vector<int>;
using VLL = vector<ll>;
using VS = vector<string>;
using VSH = vector<short>;
using VULL = vector<ull>;

const int MOD = 1000000007;
const int INF = 1000000000;
const int NIL = -1;

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



int main(){
    string S, T; cin >> S >> T;
    cout << T << S << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n) ; i++)
#define rrep(i,n) for(int i = n-1; i >= 0 ; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main(){
    string s, t;
    cin >> s >> t;
    int ans = 0;
    rep(i, s.length()){
        if(s[i] != t[i]) ans++;
    }

    cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3864
from math import *

def cin(): # To take limited number of inputs
    return map(int,input().split())

def cins(): # To take space sepreated strings
    return input.split()

def cino(test=False): # To take individual int input (test = False)
    if not test:
        return int(input())
    else: # To take string input (test = True)
        return input()

def cina(): # array input
  return list(map(int,input().split()))

def ssplit(): # multiple string input
    return list(input().split())

def printlist(l): # To print space seperated array
    for i in l:
        print(i,end=" ")

def main():
    a = cino()
    # s = cino(True)
    # a,b = cin()
    print("Yes" if a>= 30 else "No")

if __name__ == '__main__':
    main()

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

int main(){
  string s,t; 
  cin>>s>>t;
  int sn=s.length(),tn=t.length();
  bool f=true;
  for(int i=sn-tn;i>=0;i--){
    bool accept=false;
    for(int j=i;j<i+tn;j++){
      if(s[j]!=t[j-i]&&s[j]!='?') break;
      if(j==i+tn-1) accept=true;
    }
    if(accept){
      f=false;
      for(int j=i;j<i+tn;j++){
        s[j]=t[j-i];
      }
      for(int j=0;j<sn;j++) if(s[j]=='?')s[j]='a';
      cout<<s<<endl;
      break;
    }
  }
  if(f) cout<<"UNRESTORABLE"<<endl;
  return 0;
}


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

using namespace std;
#define rep(i,n) for (int i =0;i<(n);++i)
using ll = long long;
using P = pair<int, int>;

int main() {
	vector<int> N(3);
	cin >> N[0] >> N[1]>>N[2];
	int a = 0;
	sort(N.begin(), N.end());
		for (int i = 0;i < 2;i++) {
			if (N[i] != N[i + 1]) a++;
		}
		if (a != 1)cout << "No";
		else cout << "Yes";
	}
	

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n;
	while(cin>>n,n){
		vi l(n);
		rep(i,n)cin>>l[i];
		int A,C,S;
		double mi=1e8;
		rep(s,16)rep(a,16)rep(c,16){
			vi R(n+1);
			R[0]=s;
			loop(i,1,n+1)R[i]=(a*R[i-1]+c)%256;
			vi X(260,0);
			rep(i,n)X[(R[i+1]+l[i])%256]++;
			double sum=0;
			rep(i,260)if(X[i])sum-=(double)X[i]/n*log((double)X[i]/n);
			if(mi>1e-9+sum){
				mi=sum;
				A=a;C=c;S=s;
			}
		}
		cout<<S<<" "<<A<<" "<<C<<endl;
	}
}

Measured memory_bytes: 1240
#include<stdio.h>
int main(void) {
	int a, b, c, d, e, f, g, h, i, j, sum;
	scanf("%d %d %d %d %d %d %d %d %d %d",&a,&b,&c,&d,&e,&f,&g,&h,&i,&j);
	sum = a + b + c + d + e + f + g + h + i + j;
	printf("%d\n",sum);
	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>

int A[1000000], n;


int binarySearch(int key) {
	int left = 0;
	int right = n;
	int mid;
		while ( left < right ) {
			mid = (left+right) / 2;
			if ( key == A[mid] ) return 1;
			if ( key >A[mid] ) left = mid + 1;
			else if ( key < A[mid] ) right = mid;
		}
			return 0;
		}
	

  
  int main(){
   int i, q, k, sum = 0;
  
   scanf("%d", &n);
   for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
   
   scanf("%d", &q);
   for ( i = 0; i < q; i++ ){
    scanf("%d", &k);
    if ( binarySearch( k ) ) sum++;
    }
    printf("%d\n", sum);
    
    return 0;
   }
    


Measured memory_bytes: 2180
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<set>
#include<functional>
using namespace std;

#define INF 1<<21
#define MOD 1000000007

int main() {
  int n;
  string s1, s2;
  int x, y;
  int mul;
  cin >> n;
  for (int i = 0; i < n; i++) {
	x = 0; y = 0;
	cin >> s1 >> s2;
	int kk = 1;
	for (int j = 0; j < s1.length(); j++) {
	  switch (s1[j]) {
	  case 'm':
		x += 1000*kk;
		kk = 1;
		break; 
	  case 'c':
		x += 100*kk;
		kk = 1;
		break;
	  case 'x':
		x += 10 * kk;
		kk = 1;
		break;
	  case 'i':
		x += kk;
		kk = 1;
		break;
	  default:kk = s1[j] - '0';
	  }
	}
	kk = 1;
	for (int j = 0; j < s2.length(); j++) {
	  switch (s2[j]) {
	  case 'm':
		x += 1000 * kk;
		kk = 1;
		break;
	  case 'c':
		x += 100 * kk;
		kk = 1;
		break;
	  case 'x':
		x += 10 * kk;
		kk = 1;
		break;
	  case 'i':
		x += kk;
		kk = 1;
		break;
	  default:kk = s2[j] - '0';
	  }
	}
	int o, p;
	o = (x + y) / 1000;
	if (o>1)cout << o << "m";
	if (o == 1)cout << "m";
	o = (x + y) % 1000;
	p = o / 100;
	if (p>1)cout << p << "c";
	if (p == 1)cout << "c";
	p = o % 100;
	o = p / 10;
	if (o>1)cout << o << "x";
	if (o == 1)cout << "x";
	o = (x + y) % 10;
	p = o / 1;
	if (p>1)cout << p << "i";
	if (p == 1)cout << "i";
	cout << endl;
  }
}

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

//Coding below.
int main (){
    int A,B;
    cin >> A >> B;
    int plus,minus,multi;
    int ans;
    plus = A+B;
    minus = A-B;
    multi = A*B;
    ans = plus;
    if(ans < minus){
        ans = minus;
    }
    if(ans < multi){
        ans = multi;
    }
    cout << ans;
    
}

Measured memory_bytes: 256
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;


/* TEMPLATE ENDS HERE */

#define N 15
#define EPS 1e-9

int k;
vector<ll> vv;

ll dig(ll k) {
	ll ret = 0;
	while (k) {
		ret += k % 10;
		k /= 10;
	}
	return ret;
}

ld f(ll k) {
	return (ld) k / (ld) dig(k);
}

vector<ld> fs;

int main() {
	cout << fixed << setprecision(12);	
	cin >> k;
	ll ten = 1;
	for (int d = 1; d <= N + 1; d++) {
		for (int i = 1; i < 10000; i++) {
			ld curd = i * (ld) ten + (ld)ten - 1;
			if (curd > (ll)1e16) {
				continue;
			}
			ll cur = i * ten + (ten - 1);			
			vv.push_back(cur);		
		}
		if (d >= 3) {
			ten *= 10;
		}
	}
	set<ll> s(vv.begin(), vv.end());
	vector<ll> v(s.begin(), s.end());

	int n = v.size();
	for (int i = 0; i < n; i++) {
		fs.push_back(f(v[i]));
	}
	
	vector<ld> m(n);
	m[n - 1] = fs[n - 1];
	for (int i = n - 2; i >= 0; i--) {
		m[i] = min(m[i + 1], fs[i]);
	}
	vector<ll> ans;
	for (int i = 0; i < n - 2; i++) {
		if (fs[i] <= m[i + 1] + EPS) {
			ans.push_back(v[i]);
		}
	}
	for (int i = 0; i < min(k, (int)ans.size()); i++) {
		cout << ans[i] << endl;
	}
	//cerr << ans.size() << endl;
	return 0;
}


ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
		x %= MOD;
	}
	
	mod& operator=(const ll & tx) {
		x = tx % MOD;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return mod((x + m2.x) % MOD);
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return mod((x - m2.x + MOD) % MOD);
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return mod((x * m2.x) % MOD);
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return (*this) * m2.inv();
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}



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

#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define INF  (1<<30)
#define INFL (1LL<<60)
#define MOD 1000000007
#define EPS ((ld)(1e-9))

#define sz(x) ((int)(x).size())
#define setz(x) memset(x, 0, sizeof(x))
#define rep(i, x)  for (int i = 0, _##i = (x); i < _##i; i++)
#define repp(i, x) for (int i = 1, _##i = (x); i <= _##i; i++)
#define repr(i, s, e) for (int i = (s), _##i = (e); i < _##i; i++)

#define L(x) ((x)*2)
#define R(x) ((x)*2+1)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<ll, ll> pll;

template<typename T, typename V>
ostream &operator<<(ostream &os, const pair<T, V> pai) { 
    os << pai.first << ' ' << pai.second;
	return os;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> v) {
    rep(i, sz(v)) cout << v[i] << ' ';
    return os;
}

template<typename T, typename V>
istream &operator>>(istream &is, pair<T, V> &pai) {
	is >> pai.first >> pai.second;
	return is;
}

ll K, A, B;

int main(void) {
    iostream::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    
    cin >> K >> A >> B;

    if (B-A <= 2 or K <= A) {
        cout << K+1;
        return 0;
    }
    
    K -= A-1;
    ll bis = A+(B-A)*(K/2)+(K&1);
    cout << bis;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

main(){
	int a,b,c,k,count=1;
	
	cin>>a>>b>>c;
	while(count!=0){
	count=0;
		if(c<b){
		k=c;
		c=b;
		b=k;
		count++;
	}
	if(a>b){
		k=a;;
		a=b;
		b=k;
		count++;
	}
	}
	cout<<""<<a<<" "<<b<<" "<<c<<endl;
}	

Measured memory_bytes: 1164
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split(" ");
		int a = Integer.parseInt(tokens[0]);
		int b = Integer.parseInt(tokens[1]);
		int diff = b - a;
		System.out.println((sum(diff) - b));

		in.close();
	}

	private static int sum(int diff) {
		int result = 0;
		for (int i = 0; i <= diff; ++i) {
			result += i;
		}
		return result;
	}

}

Measured memory_bytes: 21844
#include <stdio.h>

void color(int map[10][10], int x, int y)
{
  if (0 <= x && x <= 9 && 0 <= y && y <= 9){
    map[y][x]++;
  }
}

int main(void)
{
  int map[10][10] = {0};
  int x, y, size;
  int i, j;
  int white = 0, mostdark = 0;

  while (scanf("%d,%d,%d", &x, &y, &size) != EOF){
    map[y][x]++;
    if (size == 3){
      color(map, x + 2, y);
      color(map, x - 2, y);
      color(map, x, y + 2);
      color(map, x, y - 2);
    }
    if (size >= 2){
      color(map, x + 1, y + 1);
      color(map, x - 1, y + 1);
      color(map, x + 1, y - 1);
      color(map, x - 1, y - 1);
    }
    if (size >= 1){
      color(map, x, y + 1);
      color(map, x, y - 1);
      color(map, x + 1, y);
      color(map, x - 1, y);
    }
  }

  for (i = 0; i < 10; i++){
    for (j = 0; j < 10; j++){
      if (map[i][j] == 0){
        white++;
      }
      if (mostdark < map[i][j]){
        mostdark = map[i][j];
      }
    }
  }

  printf("%d\n%d\n", white, mostdark);

  return (0);
}

Measured memory_bytes: 600
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
cd=[list(map(int,input().split())) for _ in range(n)]
ab.sort(key=lambda x:x[0])
cd.sort(key=lambda x:x[0])
ans=0
i=0
red_x=[]
import bisect
for c,d in cd:
  while i<n and ab[i][0]<c:
    bisect.insort_right(red_x,ab[i][1])
    i+=1
  if red_x and red_x[0]<d:
    idx=bisect.bisect_right(red_x,d)-1
    ans+=1
    red_x.pop(idx)
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
//もう二度とつかわん//
//    ↓ ↓　↓　　 //
#define ll long long
//    ↑　↑　↑    //
//フェルマー方程式の恨み//
#define rep(i,n) for(int i=0;i<n;i++)
#define ggr getchar(); getchar();return 0;
using namespace std;
char a[55][55];
signed main() {
	ll h, w;
	cin >> h >> w;
	rep(i, h) { rep(j, w)cin >> a[i][j]; }
	rep(i, h) {
		rep(j, w) {
			if (a[i][j] == '#') {
				if (a[i][j - 1] != '#' && a[i][j + 1] != '#' && a[i + 1][j] != '#' && a[i - 1][j] != '#') {
					puts("No");
					ggr
				}
			}
		}
	}
	puts("Yes");
	ggr
}

Measured memory_bytes: 256
h,n=map(int,input().split())

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

INF=float("inf")

dp=[INF]*(h+1)
dp[h]=0

for a,b in skills:
    for hh in range(h,0,-1):
        if hh-a>=0:
            dp[hh-a]=min(dp[hh-a],dp[hh]+b)
        else:
            dp[0]=min(dp[0],dp[hh]+b)          
            
print(dp[0])


Measured memory_bytes: 50140
from collections import deque

class PriorityQueue:
    def __init__(self):
        self.nodes = []

    def max_heapify(self, i):
        if i >= len(self.nodes): return
        left, right = (i+1)*2-1, (i+1)*2

        largest = i
        if left < len(self.nodes) and self.nodes[i] < self.nodes[left]: largest = left
        if right < len(self.nodes) and self.nodes[largest] < self.nodes[right]: largest = right

        if largest != i:
            self.nodes[i], self.nodes[largest] = self.nodes[largest], self.nodes[i]
            self.max_heapify(largest)

    def print_element(self):
        for node in self.nodes:
            print('', node, end='')
        print('')

n = int(input())
A = list(map(int, input().split(' ')))

pq = PriorityQueue()
pq.nodes = A

for i in range((n-1)//2, -1, -1):
    pq.max_heapify(i)

pq.print_element()


Measured memory_bytes: 60532
#!/usr/bin/env ruby
s = gets.chomp

acgt = %w[A C G T]
ans = 0

10.times do |i|
  len = 0

  j = i
  while j < 10
    break unless acgt.include?(s[j])
    len += 1
    j += 1
  end

  ans = [ans, len].max
end

puts ans


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

int main() {
  int n,a,max_l;
  cin >> n;
  priority_queue<int> l;
  for(int i=0;i<n;i++) {
    cin >> a;
    l.push(a);
  };
  max_l=l.top();
  l.pop();
  a=0;
  for(int i=0;i<n-1;i++) {
    a+=l.top();
    l.pop();
  };
  if(max_l<a) cout << "Yes" << endl;
  else cout << "No" << endl;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    lli n;
    cin >> n;

    vector<lli> v(n);
    lli total_sum = 0;

    for(lli i = 0; i < n; i++)
    {
        cin >> v[i];
        total_sum += v[i];
    }

    lli current_sum = 0;
    lli answer = 0;

    for(int i = 0; i < n; i++)
    {
        current_sum += v[i];
        lli factor = total_sum - current_sum;
        factor = factor%(1000000000 + 7);

        answer += v[i]*factor;
        answer = answer%(1000000000 + 7);

    }

    cout << answer << endl;

}



Measured memory_bytes: 4760
#include <iostream>
using namespace std;
int main(){
	int n,d,x[10][10]={};
	cin >> n >> d;
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin >> x[i][j];
		}
	}
	int ct=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			if(i<j){
				int dis=0;
				for(int k=0;k<d;k++){
					dis+=(x[i][k]-x[j][k])*(x[i][k]-x[j][k]);
				}
				for(int k=0;k<400;k++){
					if(dis==k*k){
						ct++;
					}
				}
			}
		}
	}
	cout << ct << endl;
}


Measured memory_bytes: 256
N = int(input())
restaurants = dict()
ans = list()
target = list()
for i in range(N):
	S = list(map(str,input().split()))
	if S[0] not in restaurants :
		restaurants[S[0]] = [int(S[1])]
	else:
		dict_key = restaurants[S[0]]
		dict_key.append(int(S[1]))
		dict_key.sort(reverse=True)
		restaurants[S[0]] = dict_key
	target.append(S[0]+' '+S[1])


restaurants_sorted = sorted(restaurants.items(), key=lambda x:x[0])
# print(restaurants_sorted)
# print(restaurants_sorted[0])
for idx in range(len(restaurants_sorted)):
	for i in range(len(restaurants_sorted[idx][1])):
		print(target.index(restaurants_sorted[idx][0]+' '+str(restaurants_sorted[idx][1][i]))+1)

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


int main(){
    int n,kk;
    cin>>n>>kk;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    ll ans=0;
    for(int i=-1;i<n;i++){
        for(int j=n;j>=0&&i<j;j--){
            if(i+1+n-j>kk) continue;
            ll sum=0;
            //ll dec=0;
            priority_queue<ll,vector<ll>,greater<ll>> que;
            for(int k=0;k<=i;k++){
                que.push(a[k]);
                sum+=a[k];
            }
            for(int k=j;k<n;k++){
                que.push(a[k]);
                sum+=a[k];
            }
            for(int k=0;k<kk-(i+1+n-j)&&que.size();k++){
                ll p=que.top();
                que.pop();
                if(p>=0) break;
                sum-=p;
            }
            ans=max(ans,sum);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3604
//----------------------------templates
    #pragma GCC optimize ("Ofast")
    #pragma GCC target ("tune=native")
    #pragma GCC target ("avx")
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;

//--------------------------------------------

int sqrtint(int v){
    int lo = 0;
    int hi = INT_MAX-2;
    while(hi-lo > 1){
        int mid = (lo+hi)/2;
        if (mid * mid <= v){
            lo = mid;
        } else {
            hi = mid;
        }
    }
    return lo;
}


int q,a,b,score,r;
signed main(){
    I(q);
    REP(i,q){
        I(a); I(b);
        score = a*b-1;
        int sq = sqrtint(score);
        r = sq*2;
        if (a <= sq) r--;
        if (b <= sq) r--;
        if (sq*(sq+1) > score) r--;
        cout << r << endl;
    }
}

Measured memory_bytes: 256
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#include <numeric>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,a,n) for(int i=a;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef long long ll;

const int INF=1000000;
char fi[101][101];
int d[21][21];
int day[12]={31,28,31,30,31,30,31,31,30,31,30,31};
double EPS = 1e-10;
int N,M;
int sx,sy;
int gx,gy;
int w,h;
int ans;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};
const int MAX_V=100;
const int MAX_N=100;
char o[3]={'+','-','*'};
#define md 1000003


int dp[353][353]={0};
int bow[353][353]={0};
double add(double a,double b){
	if(abs(a+b)<EPS*(abs(a)+abs(b)))
	return 0;
	return a+b;
}

struct P{
	double x,y;
	P(){}
		P(double x,double y):x(x),y(y){
		}
		P operator + (P p){
			return P(add(x,p.x),add(y,p.y));
		}
		P operator - (P p){
			return P(add(x,-p.x),add(y,-p.y));
		}
		P operator *(double d){
			return P(x*d,y*d);
		}
		double dot(P p){
			return add(x*p.x,y*p.y);
		}
		double det(P p){
			return add(x*p.y,-y*p.x);
		}
};

bool cmp_x(const P& p,const P& q){
	if(p.x!=q.x) return p.x<q.x;
	return p.y<q.y;
}

vector<P> convex_hull(P* ps, int n){
	sort(ps,ps+n,cmp_x);
	int k=0;
	vector<P> 	qs(n*2);
	
	rep(i,n){
		while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
			k--;
		qs[k++]=ps[i];
	}
	for(int i=n-2,t=k;i>=0;i--){
		while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0)
		k--;
		qs[k++]=ps[i];
	}
	qs.resize(k-1);
	return qs;
}

int n;
P ps[101];

int main(){
	
	int h,w;
	
	while(cin>>h>>w,h!=0||w!=0){
		
		rep(j,w)
		cout<<"#";
		cout<<endl;
		
		REP(i,1,h-1){rep(j,w){
			if(j==0||j==w-1)
		cout<<"#";
			else
			cout<<".";
		}
			cout<<endl;
		}
		rep(j,w)
		cout<<"#";
		cout<<endl;
		cout<<endl;
	}
	
	
	
	
	
	
	

	
}

Measured memory_bytes: 1156
#define  _CRT_SECURE_NO_WARNINGS
	#include <algorithm>
	#include <iostream>
	#include <iterator>
	#include <numeric>
	#include <sstream>
	#include <fstream>
	#include <cassert>
	#include <climits>
	#include <cstdlib>
	#include <cstring>
	#include <string>
	#include <cstdio>
#include<algorithm>
	#include <vector>
	#include <math.h>
	#include <queue>
	#include<memory>
	#include <deque>
	#include <stack>
	#include <list>
	#include <map>
	#include <set>
	#include <cmath>
	#include <bitset>
	#include<list>
	#include <iomanip>
	using namespace std;
	typedef long long ll;
	char maze[3000][3000];
	int r, c;
	long long dp[3000][3000];
	bool vis[(int)1e5 + 10];
	vector<int> graph[(int)1e5 + 10];
	
	long long solve(int i, int j)
	{
		dp[0][0] = 1;
		for (int i = 0; i < r; i++)
		{
			for (int j = 0; j < c; j++)
			{
				if (maze[i][j] == '#')continue;
				if (maze[i - 1][j] == '.' && maze[i][j - 1] == '.')
					dp[i][j] =( dp[i - 1][j] + dp[i][j - 1] )% ((long long)1e9 + 7);
				else if (maze[i][j - 1] == '.')
					dp[i][j] = dp[i][j - 1];
				else if (maze[i - 1][j] == '.')dp[i][j] = dp[i - 1][j];
			}
		}
		return dp[r - 1][c - 1];
	}
	int solv1(int i, int j)
	{
		if (maze[i][j] == '#')return 0;
		if (i == r - 1 && j == c - 1 && maze[i][j]=='.')return 1;
		if (i == r)return 0;
		if (j == c)return 0;
		if (dp[i][j] != -1)return dp[i][j];
		return dp[i][j] = (solv1(i + 1, j) + solv1(i, j + 1)) % ((int)1e9 + 7);;
	}
	
	int main()
	{

		memset(dp, -1, sizeof dp);
		cin >> r >> c;
		for (int i = 0; i < r; i++)
		{
			for (int j = 0; j < c; j++)
			{
				cin >> maze[i][j];
			}
		}
		solv1(0, 0) ;;
		cout << dp[0][0] << endl;
		return 0;
	}

Measured memory_bytes: 76160
#include<bits/stdc++.h>
using namespace std;
                    
                    
int main(){
    int x1, x2, x3, x4, x5, ans;
    cin >> x1 >> x2 >> x3 >> x4 >> x5;

    if(x1 == 0){
        ans = 1;
    } else if (x2 == 0) {
        ans = 2;
    } else if (x3 == 0) {
        ans = 3;
    } else if (x4 == 0) {
        ans = 4;
    } else if (x5 == 0) {
        ans = 5;
    }

    cout << ans << endl;

    return 0;
            
}

Measured memory_bytes: 3596
k=int(input())
x=set()
for i in range(1,10):
	x.add(i)

while len(x)<=10**5:
	y=list(x)
	for i in y:
		j=int(str(i)[-1])
		l=i*10+(j-1)
		m=i*10+j
		r=i*10+(j+1)
		x.add(m)
		if j!=0:
			x.add(l)
		if j!=9:
			x.add(r)

y=sorted(list(x))

print(y[k-1])

Measured memory_bytes: 29892
#include "bits/stdc++.h"

#define rep(a,b) for(int a = 0;a < b;a++)
#define REP(i, x, n) for(int i = x; i < n; i++)
#define P(a) cout << a << endl
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define ssort(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vP(v) for(int i = 0;i < v.size();i++){cout << v[i];if(i != v.size()-1)cout << endl;}
#define vcin(v,n) rep(i,n){int a;cin >> a;v.pb(a);}

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int dx[] = { 1, -1 , 0 , 0 };
int dy[] = { 0,  0,  1, -1 };
//int dx[] = { 1, 0 };
//int dy[] = { 0, 1 };
#define mod7 1e9+7;
#define mod9 1e9+9;

int nextInt(){
	int a;	cin >> a;return a;
}
string next(){
	string s;cin >> s;return s;
}
char nextChar(){
	char c;cin >> c;return c;
}

unsigned long long strtoint(std::string str) {
	unsigned long long ret;
	std::stringstream ss; ss << str;
	ss >> ret;
	return ret;
}

void solve(){
	int n = nextInt();
	vector<pair<ll,ll>> v;
	rep(i,n){
		int a = nextInt();
		int b = nextInt();
		v.pb(mp(a,b));
	}
	ssort(v);
	ll count = 0;
	ll pos = 0;
	ll point = 1e10;
	rep(i,n){
		count += min(abs(v[i].second-point),abs(v[i].first-pos)-1);
		point = v[i].second;
		pos = v[i].first;
	}
	count += v[v.size()-1].second;
	P(count+n);
}

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


Measured memory_bytes: 2548
N = int(input())
l = [None] * N
m = -float("inf")
m2 = -float("inf")
for i in range(N):
    l[i] = int(input())
    
    if (l[i] > m):
        m2 = m
        m = l[i]
    elif (l[i] > m2):
        m2 = l[i]


for el in l:
    if el == m:
        print(m2)
    else:
        print(m)    



Measured memory_bytes: 12508
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef long double ld;

ll inv(ll a, ll b){
    return (a > 1 ? b - inv(b%a, a)*b/a : 1);
}

#define rc(s) return cout << s, 0
#define fi first
#define se second
#define L (nod << 1)
#define R (L | 1)
#define smax(X, Y) ((X) > (Y) ? (X) : (Y))
#define smin(X, Y) ((X) < (Y) ? (X) : (Y))
#define N 1005

const ld e = 2.71828182845904523536028747;
const ld PI = 3.14159265359;
const ll inf = (1LL<<62);
const int iinf = (1<<30);

int mx = 1, n, m, d[N][N];
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
bool a[N][N];
queue <pii> Q;
char c;

bool ok(int i, int j){
    if (i < 1 || j < 1 || i > n || j > m) return 0;
    if (a[i][j] || d[i][j]) return 0;
    return 1;
}

int main(){
    cin >> n >> m;
    for (int i=1; i<=n; i++)
         for (int j=1; j<=m; j++){
            cin >> c;
            a[i][j] = (c == '#');
            if (!a[i][j]) continue;
            Q.push({i, j});
            d[i][j] = 1;
        }
    while (!Q.empty()){
        int i = Q.front().fi, j = Q.front().se;
        Q.pop();
        for (int dir=0; dir < 4; dir++){
            int i2 = i + dx[dir], j2 = j + dy[dir];
            if (ok(i2, j2)) d[i2][j2] = d[i][j] + 1, mx = smax(mx, d[i2][j2]), Q.push({i2, j2});
        }
    }
    cout << mx - 1;
    return 0;
}


Measured memory_bytes: 13328
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
ll dp[100000+10][2][105];
string s;
int d;
ll digit_dp(ll pos, ll tgt, ll sum)
{
	if(pos==(ll)s.size())
	{
		if(sum==0)
			return 1ll;
		return 0ll;
	}
	if(dp[pos][tgt][sum]!=-1)
	return dp[pos][tgt][sum];
	
	ll ans=0;
	if(tgt==1)
	{
		for(int i=0;i<=s[pos]-'0';i++)
		{
			if(i==s[pos]-'0')
				ans = ans + digit_dp(pos+1,1,(sum+i)%d);
			else
				ans = ans + digit_dp(pos+1,0,(sum+i)%d);
			
			ans=ans%mod;
		}
		
	}
	else
	{
		for(int i=0;i<=9;i++)
		{
			ans = ans + digit_dp(pos+1, 0, (sum+i)%d);
			ans=ans%mod;
		}
	}
	return dp[pos][tgt][sum]=ans%mod;
	
}

int main()
{
	cin>>s;
	cin>>d;
	memset(dp,-1,sizeof(dp));
	
	ll ans = digit_dp(0,1,0)-1ll;
	if(ans==-1)
	ans=mod-1;
	
	cout<<ans;
} 


Measured memory_bytes: 168472
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;

struct Struct {
    int num1;
    int num2;
    int num3;

    Struct(int n1, int n2, int n3) {
        num1 = n1;
        num2 = n2;
        num3 = n3;
    }

    bool operator<(const Struct& another) const {
      if(num1 == another.num1){
        return num2 < another.num2;
      }
      else{
        return num1 < another.num1;}
    }
};

int main(){
int N,Q;
long long S,T,X;
cin>>N>>Q;
set<long long> cur;
vector<Struct> v;
for(int i=0;i<N;++i){
  cin>>S>>T>>X;
  //S-X<=start time<T-XならXiで止まる
  v.push_back(Struct(S-X,1,X));
  v.push_back(Struct(T-X,-1,X));
}
sort(v.begin(),v.end());
long long q;
long long counter=0;
for(int i=0;i<Q;++i){
  cin>>q;
  while(v[counter].num1<=q && counter<2*N){
    if(v[counter].num2==-1){
      cur.erase(v[counter].num3);
    }
    else if(v[counter].num2==1){
      cur.insert(v[counter].num3);
    }
    counter+=1;
  }
  if(cur.size()==0){
    cout<<-1<<"\n";
  }
  else{
  auto itr=cur.begin();
  cout<<*itr<<"\n";}
}
return 0;
}

Measured memory_bytes: 15724
n, m = map(int, input().split())
N = []
M = []
for i in range(n):
    N.append(input())
for i in range(m):
    M.append(input())

for i in range(n-m+1):
    if not M[0] in N[i]:
        continue
    else:
        pos = N[i].index(M[0])
        flag = True
        for j in range(m):
            if M[j] != N[i+j][pos:pos+m]:
                flag = False
                break
        if flag:
            print("Yes")
            exit()
print("No")

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

int main(){
    int i,n;
    char str[101];

    scanf("%s",str);
    n=strlen(str);

    for(i=0;i<n;i++){
        if(i%2==0&&str[i]=='L'){
            printf("No\n");
            return 0;
        }
        if(i%2==1&&str[i]=='R'){
            printf("No\n");
            return 0;
        }
    }

    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define LL long long
#define MAXN 100005
using namespace std;

struct Node {LL x, p;} a[MAXN];

LL n, s, p;

LL doit(LL l, LL r, LL p)
{
    if(a[l].x>=s) return a[r].x-s;
    if(a[r].x<=s) return s-a[l].x;
    if(a[l].p>=a[r].p)
    {
        a[l].p+=a[r].p;
        return doit(l, r-1, l)+a[p].x-a[l].x;
    }
    else
    {
        a[r].p+=a[l].p;
        return doit(l+1, r, r)+a[r].x-a[p].x;
    }
}

int main()
{
    scanf("%lld%lld", &n, &s);
    for(int i=1; i<=n; i++) scanf("%lld%lld", &a[i].x, &a[i].p);
    if(a[1].p>=a[n].p) p=n;
    else p=1;
    printf("%lld\n", doit(1, n, p));
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <tuple>
#include <stdbool.h>
#include <bitset>
#include <string>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using namespace std;


int main(void) {
    int n,k;
    cin >> n;
    cin >> k;
    k -= 1;

    vector<mp::cpp_int> trees(n);
    for(int i = 0 ; i < n ; ++i) {
        cin >> trees[i];
    }
    sort(trees.begin(), trees.end());
    // 距離の差分で作り直す
    // ソートしてアレばk本分離れた位置がhmax-hminそのものになりそう
    mp::cpp_int min = 9999999999999999;
    for(int i = 0 ; i < n - k ; ++i) {
        auto d = abs(trees[i] - trees[i + k]);
        if (d < min) {
            min = d;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<stack>
#include<queue>
#include<bitset>

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)

using namespace std;

typedef long long int lli;
typedef vector<int> vi;

int main() {
	long long i, j, k, n;
	lli ans;
	vector<long long>s;

	cin >> n;

	s.resize(n + 1);
	s[0] = 0;
	rep(i, n) {
		cin >> j;
		s[i + 1] = s[i] + j;
	}

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

	ans = 0;

	for (i = 0; i < n; i++) {
		k = s[i];
		for (j = i + 1; j < n + 1; j++) {
			if (k != s[j])
				break;
		}
		ans += (j - i)*(j - i - 1) / 2;
		i = j - 1;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1792
// ABC_154+_C

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

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

	vector<int> vec(n);
	for(int i = 0; i < n; ++i) {
		cin >> vec[i];
	}

	int v_size = vec.size();

	set<int> s(vec.begin(), vec.end());

	if(v_size == s.size()) cout << "YES" << "\n";
	else cout << "NO" << "\n";

	return 0;
}

Measured memory_bytes: 10368
#include <iostream>
using namespace std;
int main() {
	int n, ans = 20000;
	cin >> n;
	int p[5000], q[5000];

	for (int i = 0; i < n; i++) {
		cin >> p[i];
		q[i] = p[i];
	}//??\?????¨

	for (int j = 0; j < 4; j++) {
		int counti = 0;//???????????´??§????????????
		for (int i = 0; i < n; i++)
			p[i] = q[i];
		p[0] -= j;//????????????????????????????????????

		for (int i = 0; i < n - 1; i++) {
			if (p[i] > 0) {
				counti += p[i] * 2;
				p[i + 1] -= p[i];
			}
		}
		if (p[n - 1] < 0)
			p[n - 1] = 0;
		if (ans > counti + p[n - 1] + j)
			ans = counti + p[n - 1] + j;//a[n-1]?????????????\\??????????????£????????????????????°j??????????????????????????????????????????	
	}
	cout << ans << endl;
}

Measured memory_bytes: 3140
package main

import "fmt"

func main() {
	var a, b, r int
	fmt.Scan(&a, &b)
	for i := 1; i <= a-1; i++ {
		for j := 1; j <= 31; j++ {
			if i == j {
				r++
			}
		}
	}
	for j := 1; j <= b; j++ {
		if a == j {
			r++
		}
	}
	fmt.Println(r)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define int ll
#define BUF 1e5
#define INF 1 << 30
#define vi vector<int>
#define vvi vector<vector<int>>
#define all(a) (a).begin(), (a).end()
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
constexpr ll mod = 1e9 + 7;
ll A, B, C, D, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    map<string, int> mp;
    for (int i = 0; i < N; i++) {
        cin >> S;
        sort(all(S));
        if (mp[S] > 0) {
            ans += mp[S];
        }
        mp[S]++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    int x, y;
    cin >> x >> y;
    string ans = "Yes";
    if(y>x*4) ans = "No";
    if(x*2>y) ans = "No";
    if (abs(y - x * 2) % 2 != 0 || abs(y - x * 4) % 2 != 0) ans = "No";
        cout << ans << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359

const int mod = 1e9 + 7;

vector<int> candidates;
vector<int> options = {3, 5, 7};

int N;

void generate_candidate(int depth, int num){
  if(depth == 9){
    return;
  }

  candidates.push_back(num);

  for(int o: options){
    generate_candidate(depth+1, num*10 + o);
  }
}

int cnt_candidate(){
  int ans = 0;
  for(int c: candidates){
    int cnt_7=0;
    int cnt_5=0;
    int cnt_3=0;

    if(c > N) continue;

    while(c != 0){
      int digit = c%10;
      if(digit == 7){
        cnt_7++;
      }else if(digit == 5){
        cnt_5++;
      }else if(digit == 3){
        cnt_3++;
      }
      c /= 10;
    }

    if(cnt_7 != 0 && cnt_5 != 0 && cnt_3 != 0){
      ans++;
    }
  }
  return ans;
}

signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  cin >> N;

  for(int o: options){
    generate_candidate(0, o);
  }

  cout << cnt_candidate() << endl;

  return 0;
}


Measured memory_bytes: 640
s = input()
if s == "SUN":
    print("7")
elif s == "MON":
    print("6")
elif s == "TUE":
    print("5")
elif s == "WED":
    print("4")
elif s == "THU":
    print("3")
elif s == "FRI":
    print("2")
elif s == "SAT":
    print("1")

Measured memory_bytes: 3060
package main

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

type City struct {
	n int
	p int
	y int
}

type Citys []City

func (l Citys) Len() int {
	return len(l)
}

func (l Citys) Less(i, j int) bool {
	if l[i].p == l[j].p {
		return l[i].y < l[j].y
	}
	return l[i].p < l[j].p
}

func (l Citys) Swap(i, j int) {
	l[i], l[j] = l[j], l[i]
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	sc.Text()
	sc.Scan()
	m, _ := strconv.Atoi(sc.Text())

	citys := make(Citys, m)
	for i := 0; i < m; i++ {
		sc.Scan()
		p, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		y, _ := strconv.Atoi(sc.Text())
		citys[i] = City{i, p, y}
	}

	sort.Sort(citys)
	ans := make([]string, m)
	last := citys[0].p
	n := 0
	for _, c := range citys {
		if c.p == last {
			n++
		} else {
			n = 1
			last = c.p
		}
		ans[c.n] = fmt.Sprintf("%06d%06d", c.p, n)
	}

	for _, a := range ans {
		fmt.Println(a)
	}
}


Measured memory_bytes: 10496
import sys
readline=sys.stdin.readline

K,N=map(int,readline().split())
A=list(map(int,readline().split()))

maxdiff=K-(A[-1]-A[0])
for i in range(1,len(A)):
  if abs(A[i]-A[i-1])>maxdiff:
    maxdiff=abs(A[i]-A[i-1])
print(K-maxdiff)


Measured memory_bytes: 25880
#include <iostream>

using namespace std;

int main()
{

    int n;  cin >> n;

    int x = 1, y = 1, z = 1, fn = 0;

    int* arr = new int[n+1];
    for (int i = 0; i <= n; i++){
        arr[i] = 0;
    }

    while (true){

        while (true){

            while (true){

                fn = x*x + y*y + z*z + x*y + y*z + x*z;
                z++;

                if (fn <= n){
                    arr[fn]++;
                } else {
                    break;
                }
            }

            y++; z = 1;
            fn = x*x + y*y + z*z + x*y + y*z + x*z;

            if (fn <= n){
                continue;
            } else {
                break;
            }
        }

        x++; y = 1; z = 1;
        fn = x*x + y*y + z*z + x*y + y*z + x*z;

        if (fn <= n){
            continue;
        } else {
            break;
        }
    }

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

    return 0;
}


Measured memory_bytes: 3164
#include<stdio.h>
    int main(){
        int A, B;
            scanf("%d %d", &A, &B);
        if (1 <= A && A <= 9 && 1 <= B && B <= 9){
                printf("%d", A * B);
        }
        else if(A < 1 || 9 < A || B < 1 || 9 < B){
                printf("%d", -1);
        }else{}
    return 0;
    }


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

using namespace std;

struct S{
  int x,l,o,t,n;
  bool operator<(S s)const{
    return (t!=s.t)?t>s.t:n>s.n;
  }
};

vector<string> names;
set<int> lines[123456];
set<int> u[123456][2];
vector<string> s[52345];
vector<int> t[52345];
map<int,set<int> > idtox[52345];

int to_num(string s){
  return lower_bound(begin(names),end(names),s)-begin(names);
}


int main(){
  int N,T;
  cin>>N>>T;
  string A,B;
  cin>>A>>B;
  priority_queue<S> que;
  for(int i=0;i<N;i++){
    int a;
    cin>>a;
    s[i].resize(a);
    for(int j=0;j<a;j++){
      cin>>s[i][j];
      names.push_back(s[i][j]);
      if(s[i][j]==A){
	que.push({j,i,1,0,0});
      }
    }
    t[i].resize(a-1);
    for(int j=0;j<a-1;j++){
      cin>>t[i][j];
    }
  }
  sort(begin(names),end(names));
  names.erase(unique(begin(names),end(names)),end(names));
  for(int i=0;i<N;i++){
    for(auto e:s[i]){
      lines[to_num(e)].insert(i);
    }
    for(int j=0;j<s[i].size();j++){
      idtox[i][to_num(s[i][j])].insert(j);
    }
  }
  while(!que.empty()){
    auto c=que.top();
    if(s[c.l][c.x]==(B))break;
    que.pop();
    if(!u[c.x][c.o].insert(c.l).second)continue;
    if(c.o){
      que.push({c.x,c.l,0,c.t,c.n});
      auto &hset=idtox[c.l][to_num(s[c.l][c.x])];
      auto hit=hset.lower_bound(c.x);
      if(hit!=hset.begin()){
	auto fhit=hit;
	que.push({*--fhit,c.l,1,c.t,c.n});
      }
      auto hbit=hit;
      if(++hbit!=hset.end()){
	que.push({*hbit,c.l,1,c.t,c.n});
      }
      int id=to_num(s[c.l][c.x]);
      auto &lset=lines[id];
      auto it=lset.lower_bound(c.l);
      if(it!=lset.begin()){
	auto fit=it;
	--fit;
	que.push({*idtox[*fit][id].begin(),*fit,1,c.t,c.n});
      }
      auto bit=it;
      if(++bit!=lset.end()){
	que.push({*idtox[*bit][id].begin(),*bit,1,c.t,c.n});
      }
    }else{
      if(c.x){
	que.push({c.x-1,c.l,0,c.t+t[c.l][c.x-1],c.n});
      }
      if(c.x!=t[c.l].size()){
	que.push({c.x+1,c.l,0,c.t+t[c.l][c.x],c.n});
      }
      que.push({c.x,c.l,1,c.t+T,c.n+1});
    }
  }
  if(que.empty()){
    cout<<-1<<endl;
  }else{	
    cout<<que.top().t<<' '<<que.top().n<<endl;
  }
}

Measured memory_bytes: 59076