akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
using namespace std;
typedef tuple<int, int, int> T;

const int DEPTH = 17;
class SegTree {
public:
	int A[1 << (DEPTH + 1)];
	SegTree() { for (int i = 0; i < (1 << (DEPTH + 1)); i++) A[i] = 0; }
	void add(int l, int r, int v, int a = 0, int b = (1 << DEPTH), int id = 0) {
		if (a >= r || b <= l) return;
		if (l <= a && b <= r) { A[id] += v; return; }
		add(l, r, v, a, a + (b - a) / 2, id * 2 + 1);
		add(l, r, v, a + (b - a) / 2, b, id * 2 + 2);
	}
	int getValue(int pos) {
		pos += (1 << DEPTH) - 1;
		int ret = A[pos];
		while (pos > 0) {
			pos = (pos - 1) / 2;
			ret += A[pos];
		}
		return ret;
	}
};

int n, m;
vector<T> kukan; int kid = 0;
SegTree seg;

signed main() {
	int i, j;
	
	cin >> n >> m;
	for (i = 0; i < n; i++) {
		int l, r;
		cin >> l >> r;
		kukan.push_back(T(r - l + 1, l, r));
	}
	sort(kukan.begin(), kukan.end());
	
	for (i = 1; i <= m; i++) {
		int cnt = 0;
		for (j = i; j <= m; j += i) {
			cnt += seg.getValue(j);
		}
		cout << cnt + (n - kid) << endl;
		
		for (; kid < n && get<0>(kukan[kid]) <= i; kid++) {
			int l = get<1>(kukan[kid]);
			int r = get<2>(kukan[kid]);
			seg.add(l, r + 1, 1);
		}
	}
	
	return 0;
}

Measured memory_bytes: 9200
# import math
from fractions import gcd
from functools import reduce

N = int(input())
T = map(int, [input() for _ in range(N)])

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

print(lcm(T))


Measured memory_bytes: 5076
import re
s = input()
s = re.sub('eraser','0',s)
#print(s)
s = re.sub('erase','0',s)
#print(s)
s = re.sub('dreamer','0',s)
#print(s)
s = re.sub('dream','0',s)
#print(s)


print('YES' if set(s) == set('0') else 'NO')

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

int main() {
    int N;
    cin >> N;
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    sort(A.begin(), A.end(), greater<int>());
    priority_queue<tuple<ll, int, int>> p;
    p.push(make_tuple(A[0], 0, 0));
    ll cnt = 0;
    for (int i = 1; i < N; ++i) {
        auto t = p.top(); p.pop();
        cnt += get<0>(t);
        p.push(make_tuple(min(A[get<1>(t)], A[i]), get<1>(t), i));
        p.push(make_tuple(min(A[get<2>(t)], A[i]), i, get<2>(t)));
    }
    cout << cnt << endl;
}


Measured memory_bytes: 9024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
////////////////////////////



int main(){fastio
    ll n,a,b;cin>>n>>a>>b;
    
    if((b-a)%2==0){
        cout<<(b-a)/2<<endl;return 0;
    }
    ll r1=a+(b-a-1)/2;
    a=n+1-a;
    b=n+1-b;
    swap(a,b);
    ll r2=a+(b-a-1)/2;
    cout<<min(r1,r2)<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const long long INF = 1LL << 60;

int main(){
  char c[3][3];
  rep(i, 3) rep(j, 3) cin >> c[i][j];

  rep(i, 3) rep(j, 3) if(i==j) cout << c[i][j];
  cout << endl;

  return 0;
}


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

int main(){
    int T;
    cin >> T;
    for (int t = 0; t < T; t++){
        [](){
        int n;
        cin >> n;
        vector<uint64_t> A(n);
        copy_n(istream_iterator<uint64_t>(cin), n, A.begin());
        string S;
        cin >> S;

        vector<uint64_t> base;
        for (int i = n - 1; i >= 0; i--){
            auto a = A[i];
            for (const auto &b: base)
                a = min(a, a ^ b);
            if (a != 0)
                base.push_back(a);
            if (a != 0 and S[i] == '1'){
                puts("1");
                return;
            }
        }
        puts("0");
        }();
    }
}

Measured memory_bytes: 3616
#include <iostream>
#include <numeric>
#include "vector"
#include "map"
using namespace std;

typedef long long ll;
const ll M = (ll)1e9 + 7;
const int N = (int)1e6 + 10;
string verdicts[]{
        "pairwise coprime",
        "setwise coprime",
        "not coprime",
};
bool is_prime[1001];
int cnt[N];
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(auto &i : a)
        cin >> i;
    is_prime[1] = false;
    is_prime[2] = true;
    for(int i = 3; i <= 1000; i++)
        is_prime[i] = true;
    for(int i = 2; i <= 1000; i++)
        if(is_prime[i])
            for(int j = i + i; j <= 1000; j += i)
                is_prime[j] = false;
    vector<int> p;
    for(int i = 2; i <= 1000; i++)
        if(is_prime[i]) p.push_back(i);
    map<int, int> d;
    /* for(auto &x: p)
         cout << x << ' ';
     cout << endl;*/
    int answer = 2;
    int g = a[0];
    for(int i = 1; i < n; i++)
        g = gcd(a[i], g);
    if(g == 1) answer = 1;
    bool cans = true;
    for(int i = n - 1; i >= 0; i--) {
        for(auto j : p) {
            if(j * j > a[i])
                break;
            if(a[i] % j == 0) {
                if(cnt[j])
                    cans = false;
                cnt[j]++;
                while(a[i] % j == 0){
                    a[i] /= j;
                }
            }
        }
        if(a[i] != 1){
            if(cnt[a[i]])
                cans = false;
            cnt[a[i]]++;
        }
    }
    if(cans)
        answer = 0;
    cout << verdicts[answer];
}

Measured memory_bytes: 10992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
    ll n;
    cin>>n;
    ll sum=0,mini=mod;
    bool ok=true;
    lol(i,n){
	ll a,b;cin>>a>>b;
	if(a!=b)ok=false;
	sum+=b;
	if(a>b)mini=min(mini,b);
    }
    if(ok)return cout<<0<<endl,0;
    return cout<<sum-mini<<endl,0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath> 
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
using namespace std;   
int main()  
{
    string s;
    cin>>s;
    for(int i=0;i<s.size()-8;i++)cout<<s[i]; 
    cout<<endl;

 //   system("pause");
    return 0;
}

Measured memory_bytes: 256
public class Main {

	private static boolean match(int[] pattern, int[] s, int pos) {
		int sp = 0;
		int cr = 0;
		for (int i = pos; i < s.length; ++i) {
			cr += s[i];
			if (pattern[sp] < cr)
				break ;
			if (pattern[sp] == cr) {
				++sp; cr = 0;
				if (sp == pattern.length)
					return true;
			}
		}
		return false;
	}
	
	private static int match(int[] pattern, int[] s) {
		for (int i = 0; i < s.length; ++i) {
			if (match(pattern, s, i))
				return i;
		}
		return -1;
	}
	
	public static void main(String[] args) {
		try (java.util.Scanner sc = new java.util.Scanner(System.in)) {
			for (;;) {
				final int[] w = new int[sc.nextInt()];
				if (w.length == 0) break ;
				for (int i = 0; i < w.length; ++i) {
					w[i] = sc.next().length();
				}
				System.out.println(match(new int[]{5, 7, 5, 7, 7}, w) + 1);
			}
		}
	}

}

Measured memory_bytes: 32240
N, M = map(int, input().split())
H = list(map(int, input().split()))
tenbou = {i+1:[] for i in range(N)}

for i in range(M):
    a, b = map(int, input().split())
    tenbou[b].append(a)
    tenbou[a].append(b)

ans = N
for i in range(len(tenbou)):
    for val in tenbou[i+1]:
        if(H[i] <= H[val-1]):
            ans -= 1
            break
print(ans)
    

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

int main() {
  int X,Y,A,B,C;
  cin >> X >> Y >> A >> B >> C;
  vector<int> a(A);
  vector<int> b(B);
  vector<int> c(C);
  for(int i=0;i<A;i++){
    cin >> a[i];
  }
  for(int i=0;i<B;i++){
    cin >> b[i];
  }
  for(int i=0;i<C;i++){
    cin >> c[i];
  }
  sort(a.rbegin(), a.rend());
  sort(b.rbegin(), b.rend());
  vector<int> d;
  for(int i=0;i<X;i++){
    d.push_back(a[i]);
  }
  for(int i=0;i<Y;i++){
    d.push_back(b[i]);
  }
  for(int i=0;i<C;i++){
    d.push_back(c[i]);
  }
  sort(d.rbegin(), d.rend());
  long long ans=0;
  for(int i=0;i<X+Y;i++){
   ans += d[i];
  }
  cout << ans << endl;
}
  
  
  
  
  
  
  
  
  

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

using namespace std;

int main()
{
	int n;
	int t[110000], x[110000], y[110000];
	cin >> n;
	t[0] = x[0] = y[0] = 0;

	for (int i = 0; i < n; i++) {
		cin >> t[i + 1] >> x[i + 1] >> y[i + 1];
	}

	bool isPossible = true;
	for (int i = 0; i < n; i++) {
		int dt = t[i + 1] - t[i];
		int dist = abs(x[i + 1] - x[i]) + abs(y[i + 1] - y[i]);
		if (dt < dist) {
			isPossible = false;
			break;
		}
		if (dist % 2 != dt % 2) {
			isPossible = false;
			break;
		}
	}

	if (isPossible) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return 0;
}


Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

char ch[55];

int h, w;

bool hhw[55][55];

int main() {
  scanf("%d%d", &h, &w);
  for(int i = 1; i <= h; i++) {
    scanf("%s", ch);
    for(int j = 0; j < w; j++) {
      if(ch[j] == '#')
        hhw[i][j + 1] = true;
    }
  }
  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      if(hhw[i][j]) {
        bool xxw = false;
        if(i > 1 && !xxw) {
          xxw = hhw[i - 1][j];
        }
        if(i < h && !xxw) {
          xxw = hhw[i + 1][j];
        }
        if(j > 1 && !xxw) {
          xxw = hhw[i][j - 1];
        }
        if(j < w && !xxw) {
          xxw = hhw[i][j + 1];
        }
        if(!xxw) {
          printf("No\n");
          return 0;
        }
      }
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long C = sc.nextLong();
		long D = sc.nextLong();

		long cnum = (B/C) - ((A-1)/C);
		long dnum = (B/D) - ((A-1)/D);
		long cdnum =(B/lcm(C,D)) - ((A-1)/lcm(C,D));

		long ans = (B-A+1) - (cnum + dnum - cdnum);
		System.out.println(ans);
	}

	//整数a,bの最大公約数
	public static long gcd(long a,long b) {
		if(b == 0) return a;
		else return gcd(b,a%b);
	}

	//整数a,bの最小公倍数
	public static long lcm(long a,long b) {
		return a*b/gcd(a,b);
	}
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <numeric>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
    int n, d;
    //vector<int> d;
    ll ans = 0;

    cin >> n >> d;

    (n % (2*d + 1) == 0) ? (ans = n / (2*d + 1)) : (ans = n / (2*d + 1) + 1); 
    cout << ans << endl;
    
}


Measured memory_bytes: 256
import sys
import math
from collections import deque
import heapq
import itertools
from decimal import Decimal
import bisect
from operator import itemgetter
MAX_INT = int(10e18)
MIN_INT = -MAX_INT
mod = 1000000000+7
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

x,N = IL()
a = IL()
a.sort()

ans = [MAX_INT, 0]

for i in range(-200, 200):
  if i not in a:
    if ans[0] > abs(i - x):
      ans = [abs(i - x), i]

print(ans[1])


Measured memory_bytes: 71016
def main():
  import sys
  input = sys.stdin.readline
  n,m=map(int,input().split())
  mod=pow(10,9)+7
  ans=[1]*(n+1)
  for _ in [0]*m:
    ans[int(input())]=0
  for i in range(n+1):
    ans[i]=ans[i] if ans[i]==0 or i<2 else (ans[i-1]+ans[i-2])%mod
  print(ans[-1])
if __name__ == '__main__':
    main()

Measured memory_bytes: 6900
def nibutan(L):
  ok = len(L)
  ng = -1
  while abs(ok - ng) > 1:
    mid = (ok + ng) // 2
    if nasu(mid, L):
      ok = mid
    else:
      ng = mid
  return ok

def nasu(n, L):
  p = L[n] + M
  if p < L[K]:
    return False
  m = (V - 1 - (n + P - 1)) * M
  if m <= 0:
    return True
  for i in range(n + 1, K + 1):
    m -= p - L[i]
    if m <= 0:
      return True
  return False

N, M, V, P = list(map(int, input().split()))
A = list(map(int, input().split()))

A.sort()
K = N - P
T = A[K]
print(N - nibutan(A))

Measured memory_bytes: 62704
(defun itb (s)
  (let ((flg 0))
    (loop for i across s do
          (if (upper-case-p i) (incf flg)))
    (if (= 2 flg) T nil)))

(let ((s (read-line)))
  (princ (if (and (equal (char s 0) #\A) (= 1 (count #\C (subseq s 2 (1- (length s))))) (itb s)) "AC" "WA")))


Measured memory_bytes: 13416
/*
...........__________                                                                           ___  __
.............|       |                                                                           |   /
.............|       |                                                                           |  /
.............|       |                               |                         __                | /      _______
.............|_______|  _______            _______   |______   ________   /|  /  |               |/       |      |
.............| \               | |      | |          |      |          | / | /   |               |\       |
.............|  \       _______| |      | |_______   |      |   _______|   |/    |               | \      |
.............|   \      |      | |      |         |  |      |  |       |   |     |               |  \     |
...........__|    \__|  |______| |______| ________|  |      |_ |_______|   |     |__|           _|   \__ _|        .

*/
#include<bits/stdc++.h>
using namespace std ;
#define int                 long long
#define ull                 unsigned long long int
#define ld                  long double
#define vi                  vector<int>
#define vii                 vector<pair<int,int>>
#define vvi                 vector<vector<int>>
#define pii                 pair<int,int>
#define prec(x)             fixed<<setprecision(15)<<x
#define all(x)              x.begin(),x.end()
#define rall(x)             x.rbegin(),x.rend()
#define rev(x)              reverse(x.begin(),x.end())
#define mset(a,b)           memset(a,b,sizeof(a))
#define mcpy(a,b)           memcpy(a,b,sizeof(a))
#define fo0(i,n)            for(int i=0,i##end=n;i<i##end;i++)
#define fo1(i,n)            for(int i=1,i##end=n;i<=i##end;i++)
#define fo(i,a,b)           for(int i=a,i##end=b;i<=i##end;i++)
#define foe(i,x)            for(__typeof((x).end())i=(x).begin();i!=(x).end();++i)
#define fre(i,x)            for(__typeof((x).rend())i=(x).rbegin();i!=(x).rend();++i)
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0)
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#define inf 1e18
const int mod=1e9+7;
const int N=2e5+9;

void raushan_kumar(){

    /////////////////variables///////////////
    int d=0,e=0,f=0,g=0;
    double f1=0.0,f2=0.0,f3=0.0;
    int flag=0,ans=0,res=0,cnt=0,sum=0;
    /////////////////////////////////////////
    int n;cin>>n;
    string s;cin>>s;
    fo0(i,n){
    	if(s[i]=='R')
    		d++;
    	if(s[i]=='G')
    		e++;
    	if(s[i]=='B')
    		f++;
    }
    g=d*e*f;
    for(int i=1;i<=n;i++){
    	for(int j=0;j<n;j++){
    		if(j-i<0 or j+i>=n) continue;
    		if(s[j-i]!=s[j+i] and s[j]!=s[j-i] and s[j]!=s[j+i]){
    			g--;
    		}
    	}
    }
    cout<<g;
    
}

int32_t main()
{
    fast;int t=1;
    //cin>>t;
    while(t--){
        raushan_kumar();
    }

}

Measured memory_bytes: 3656
#[allow(unused_imports)]
use itertools::Itertools;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;

fn main() {
    input! {
        n: usize,
        s: Bytes,
    }

    let mut res = 0;
    for i in 0..1000 {
        let a = (i/100) as u8 + b'0';
        let b = (i/10%10) as u8 + b'0';
        let c = (i%10) as u8 + b'0';

        let mut i = 0;
        while i < n && s[i] != a {
            i+=1;
        }
        i += 1;
        if i >= n { continue; }
        while i < n && s[i] != b {
            i+=1;
        }
        i += 1;
        if i >= n { continue; }
        while i < n && s[i] != c {
            i+=1;
        }
        if i >= n { continue; }
        res += 1;
    }
    println!("{}", res);
}


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

int main(){ 
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int d=0;
    int e=0;
    d=max(max(a,b),c);
    e=d;
    for(int i=0;i<k;i++){
        d*=2;
    }
cout <<a+b+c-e+d;
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long int ll;

#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)

int main(int argc, const char * argv[]) {
    
    ll N, D;
    cin >> N >> D;
    ll ans = 0;
    while (N > 0) {
        N -= 2 * D + 1;
        ans++;
    }
    cout << ans;
    
    return 0;
}


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

using namespace std;

int encode(vector<int> vi){
	int n = vi.size();
	vector<int> idx(8,0);
	int res = 0, cnt = 1;
	for(int i=0;i<n;i++){
		int cur = vi[(i+1)%n];
		if(cur != 0){
			if(idx[cur]==0) idx[cur] = cnt++;
			cur = idx[cur];
		}
		res = 8*res + cur;
	}
	return res;
}

int main(){
	int H, W;
	string s[11];
	while(cin >> H >> W){
		for(int i=0;i<H;i++) cin >> s[i];
		map< int, int > mp[2];
		mp[0][0] = 0;
		int cur = 0, next = 1;
		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				for(map<int,int>::iterator it=mp[cur].begin();it!=mp[cur].end();it++){
					int val = it->first;
					bool space = (s[i][j]!='#'), wall = (s[i][j]!='.');
					vector<int> state(W);
					for(int k=W-1;k>=0;val/=8) state[k--] = val%8;
					// FðhÁÄÈ¢}XÉÚµÄ½çFðhçÈ­ÄÍ¢¯È¢
					if((i!=0&&state[0]==0)||(j!=0&&state[W-1]==0)) space = false;

					// ãÌêÆ¯¶A¬ªÌêª¼ÉÈ¯êÎFðhçÈ­ÄÍ¢¯È¢
					if(W!=1){
						bool flg = state[0]!=0;
						for(int k=1;k<W;k++)
							if(state[0]!=0 && state[0]==state[k]) flg = false;
						if(flg) space = false;
					}

					// 1©ÂãÌ}XªóÅA¼ÉhÁÄé}Xª¶Ý·êÎFÍhêÈ¢
					if(W==1){
						if(i!=0&&state[0]==0&&it->second > 0) wall = false;
					}

					// Ú·é2ÂÌêª¯¶A¬ªÈçFÍhêÈ¢
					if(i!=0&&j!=0&&state[0]!=0&&state[0]==state[W-1]) wall = false;

					if(space){
						int t = state[0];
						state[0] = 0;
						int tmp = encode(state);
						if(!mp[next].count(tmp)) mp[next][tmp] = it->second;
						else                     mp[next][tmp] = max(mp[next][tmp], it->second);
						state[0] = t;
					}
					if(wall){
						if(j!=0&&state[W-1]!=0&&i!=0&&state[0]!=0){
							for(int k=1;k<W;k++) if(state[k]==state[W-1]) state[k] = state[0];
						}
						else if(j!=0&&state[W-1]!=0) state[0] = state[W-1];
						else if(i==0||state[0]==0) state[0] = 7;
						int tmp = encode(state);
						if(!mp[next].count(tmp)) mp[next][tmp] = it->second+1;
						else                     mp[next][tmp] = max(mp[next][tmp], it->second+1);
					}
				}
				mp[cur].clear();
				swap(cur, next);
			}
		}
		int res = -1;
		for(map<int,int>::iterator it=mp[cur].begin();it!=mp[cur].end();it++){
			bool ok = true;
			for(int i=0;i<W;i++)
				if(((it->first>>(3*i))%8) > 1) ok = false;
			if(ok) res = max(res, it->second);
		}
		cout << res << endl;
	}
}

Measured memory_bytes: 1096
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
l = groupedByValue[max(groupedByValue)]
for i in l:
    print(i)

Measured memory_bytes: 45392
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int a[4];
 for(int i=1; i<=3; i++)
     scanf("%d",&a[i]);
 sort(a+1,a+3+1);
 printf("%d",a[1]+a[2]);
 
 return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int num,x,count[1000];
  int a,i,j,k,l;
  int n[3];
  for(a=0;a<1000;a++){
    scanf("%d %d",&num,&x);
    count[a]=0;
    for(l=0;l<3;l++){
      n[l]=0;
    }
    if(num==0&&x==0){
      break;
    }
    for(i=1;i<=num;i++){
      for(j=i+1;j<=num;j++){
        for(k=j+1;k<=num;k++){
          if(i+j+k==x&&i!=j&&j!=k&&k!=i){
            if(n[0]==0&&n[1]==0&&n[2]==0){
              n[0]=i;
              n[1]=j;
              n[2]=k;
              count[a]++;
            }
            else{
              for(l=0;l<3;l++){
                if(n[l]!=i&&n[l]!=j&&n[l]!=k){
                  n[0]=i;
                  n[1]=j;
                  n[2]=k;
                  count[a]++;
                }
              }
            }
          }
        }
      }
    }
  }
  for(i=0;i<a;i++){
    printf("%d\n",count[i]);
  }
  return 0;
}

Measured memory_bytes: 2620
n=int(input())
a=list(map(int,input().split()))
odd=0
even=0
res=0
for i in range(n):
  if a[i]%4==1 or a[i]%4==3:
    odd+=1
  elif a[i]%2==0 and a[i]%4!=0:
    even+=1
  else:
    res+=1
if even<2:
  if odd+even-1<=res:
    print('Yes')
  else:
    print('No')
else:
  if odd<=res:
    print('Yes')
  else:
    print('No')

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

typedef long long ll;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define ANS(n) cout << (n) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define FORR(i,a,b) for(int i=(a);i>=(b);i--)

#define ALL(obj) (obj).begin(),(obj).end()

#define pii pair<int,int>

#define pb(a) push_back(a)
#define mp make_pair

int main()
{
	int n,x;
	cin >> n >> x;
	ll a[n];
	FOR(i,0,n)cin >> a[i];
	ll ans = 0;
	FOR(i,1,n){
		ll sum = a[i] + a[i-1];
		if(x < sum){
			ans += sum - x;
			a[i] = max(0ll, a[i] - (sum - x));
		}
	}
	ANS(ans);
	return 0;
}


Measured memory_bytes: 1024
n,l = map(int,input().split())
s=[l+i -1 for i in range(1,n+1)]
sum = 0
if max(s) < 0:
    s.remove(max(s))
elif min(s) > 0:
    s.remove(min(s))
else:
    s.remove(0)
    
for j in range(n-1):
    sum += s[j]
print(sum)

Measured memory_bytes: 3064
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int N, D, X;
	std::vector<int> A;
	std::cin >> N >> D >> X;
	A.resize(N);
	for (auto& a : A) {
		std::cin >> a;
	}
	
	int result = X;
	for (auto a : A) {
		result += (D + a - 1) / a;
	}
	std::cout << result << "\n";
}


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

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

    long a[100010],b[100010] = {0};
    for(int i=0;i<n;++i) cin>>a[i];

    sort(a, a + n);
    b[0] = -1;
    if(n % 2==1) b[n-1] = -1;
    else b[n-1] = 1;

    int x=1;
    while(x<n-1){
        b[x] = 2;
        ++x;
        if(x>=n-1)break;
        b[x] = -2;
        ++x;
    }

    sort(b,b+n);
    long suma=0;
    for(int i=0;i<n;++i){
        suma += a[i] * b[i];
    }

    for(int i=0;i<n;++i){
        b[i] = -b[i];
    }
    sort(b,b+n);
    long sumb = 0;
    for(int i=0;i<n;++i){
        sumb += a[i] * b[i];
    }

    long sum=0;
    if(suma > sumb) sum = suma;
    else sum = sumb;

    cout << sum << endl;
}





Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T> void assign(V<T>& v, int n, const T& a = T()) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


constexpr lint mod = 1e9 + 7;
inline lint emod(lint a, lint p = mod) { return (a % p + p) % p; }
inline lint invm(lint a, lint p = mod) { a %= p; return a == 1 ? 1 : -p / a * invm(p % a) % p; }
inline lint powm(lint a, lint n, lint p = mod) { return !n ? 1 : powm(a * a % p, n >> 1, p) * (n & 1 ? a : 1) % p; }

V<lint> fact, ifact;
void init_table(int n) {
  fact.assign(n + 1, 1), ifact.assign(n + 1, 1);
  for (int i = 2; i < n + 1; ++i) fact[i] = i * fact[i - 1] % mod;
  ifact[n] = invm(fact[n]);
  for (int i = n; i > 2; --i) ifact[i - 1] = i * ifact[i] % mod;
}

lint comb(lint n, lint r) {
  if (r < 0 or r > n) return 0;
  return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

lint mulcomb(lint n, lint r) {
  if (n < 1 or r < 0) return 0;
  return fact[r + n - 1] * ifact[r] % mod * ifact[n - 1] % mod;
}

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  lint n, k; cin >> n >> k;
  if (n < k) return cout << 0 << '\n', 0;
  init_table(n + k);
  lint res = 0;
  for (lint i = 0; i < k + 1; ++i) res += (k - i & 1 ? -1 : 1) * comb(k, i) * powm(i, n) % mod;
  cout << emod(res) << '\n';
}


Measured memory_bytes: 3240
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long

const int N = 15;

int n, m, x;
int c[N];
int a[N][N];
int cur[N];

int32_t main()
{
	IOS;
	cin >> n >> m >> x;
	for(int i = 0; i < n; i++)
	{
		cin >> c[i];
		for(int j = 1; j <= m; j++)
			cin >> a[i][j];
	}
	int ans = 1e18;
	for(int mask = 0; mask < (1 << n); mask++)
	{
		memset(cur, 0, sizeof(cur));
		int cost = 0;
		for(int i = 0; i < n; i++)
		{
			if(mask >> i & 1)
			{
				cost += c[i];
				for(int j = 1; j <= m; j++)
					cur[j] += a[i][j];
			}
		}
		int flag = 1;
		for(int i = 1; i <= m; i++)
			flag &= (cur[i] >= x);
		if(flag)
			ans = min(ans, cost);
	}
	if(ans > 1e15)
		ans = -1;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3696
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}
 
ll nCr(ll n, ll r){
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
 
//-----------------------ここから-----------
int main(void){
    int n;
    cin >> n;
    string s;
    cin >> s;

    char last = s[0];
    int cnt = 1;
    for(int i = 1; i < n; i++){
        if(s[i] != last){
            cnt++;
            last = s[i];
        } 
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 512
/*Whose woods these are I think I know.
His house is in the village though;
He will not see me stopping here
To watch his woods fill up with snow.

My little horse must think it queer
To stop without a farmhouse near
Between the woods and frozen lake
The darkest evening of the year.

He gives his harness bells a shake
To ask if there is some mistake.
The only other sound’s the sweep
Of easy wind and downy flake.

The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep.*/

#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007
const int maxn= 100010;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli x=0ll;
    cin>>x;
    vector<lli> v(2001);
    int ct=0;
    for(lli i=-1000;i<=1000;++i)
    {
        lli p=(1ll*i*i*i*i*i);
        v[ct]=p;
        ++ct;
    }
    for(int i=0;i<2001;++i)
    {
        for(int j=0;j<2001;++j)
        {
            if(v[i]-v[j]==x)
            {
                cout<<(i-1000)<<" "<<(j-1000)<<endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 3616
package main

import (
  "fmt"
  "math"
)
var M int =  1000000007

func main(){
  var n int
  fmt.Scan(&n)
  a := make([]int,n)
  for i:=0;i<n;i++{
    fmt.Scan(&a[i])
  }
  m := max(a)
  half := float64(m)/2
  // fmt.Println(half)
  h := float64(m)
  for i:= 0;i<n;i++{
    tmp := math.Abs(float64(a[i]) - half)
    if tmp <= math.Abs(h - half) && a[i] != m{
      h = float64(a[i])
    }
  }
  // fmt.Println(h)
  // fmt.Println(combination(m,int(h)))
  fmt.Println(m,int(h))

}

func max(nums []int) int {
    if len(nums) == 0 {
        panic("funciton max() requires at least one argument.")
    }
    res := nums[0]
    for i := 0; i < len(nums); i++ {
        res = int(math.Max(float64(res), float64(nums[i])))
    }
    return res
}

func permutation(n int, k int) int {
    v := 1
    if 0 < k && k <= n {
        for i := 0; i < k; i++ {
            v *= (n - i)
        }
    } else if k > n {
        v = 0
    }
    return v
}

func factorial(n int) int {
    return permutation(n, n - 1)
}

func combination(n int, k int) int {
    return permutation(n, k) / factorial(k)
}


Measured memory_bytes: 5504
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
typedef long long int ll;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T>
bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false;}
template<typename T>
bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false;}
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    REP(i, 0, n) {
        cin >> a[i];
    }
    sort(a.rbegin(), a.rend());
    ll ans = 0;
    REP(i, k, n) {
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<math.h>

int main(void){
    int n,d,i,j,k,cnt;
    double a,b;
    a=0,b=0;
    cnt = 0;
    scanf("%d%d",&n,&d);
    int x[n+1][d+1];
    for(i=1; i<=n; i++){
        for(j=1; j<=d; j++){
            scanf("%d",&x[i][j]);
        }
    }
//point i ,k
    for(i=1; i<=n; i++){
        for(k=1; k<=n; k++){
            if(i < k){
                for(j=1; j<=d ; j++){
                a += (x[i][j] - x[k][j])*(x[i][j] - x[k][j]);
                }
                b = sqrt(a);
                if(ceil(b) == floor(b)){
                    cnt++;
                }
                a = 0, b= 0;
            }
        }
    }

    printf("%d\n",cnt);

    return 0;
}


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

const int MAXN = 401;
typedef long long ll;
#define f first
#define s second
const ll mod = 1e9+7;

int arr[MAXN];
ll dp[MAXN][MAXN], sums[MAXN];

int main(){
    int N,cur;
    scanf("%d",&N);
    for (int i=0;i<N;i++){
        scanf("%d",&arr[i]);
        sums[i+1] = sums[i]+arr[i];
        for (int j=0;j<N;j++){
            dp[i][j] = 1e15;
        }
        dp[i][i] = 0;
    }
    for (int i=1;i<=N;i++){ //size of segment
        for (int j=0;j<N-i;j++){
            for (int k=j;k<j+i;k++){
                dp[j][j+i] = min(dp[j][j+i],dp[j][k]+dp[k+1][j+i]+sums[j+i+1]-sums[j]);
            }
        }
    }
    printf("%lld\n",dp[0][N-1]);
}

Measured memory_bytes: 1536
x,y = list(map(int, input().split()))

if x == 1:
  a = 300000
elif x == 2:
  a = 200000
elif x == 3:
  a = 100000
else:
  a = 0

if y == 1:
  b = 300000
elif y == 2:
  b = 200000
elif y == 3:
  b = 100000
else:
  b = 0

if x == 1 and y == 1:
  c = 400000
else:
  c = 0

print(a+b+c)

Measured memory_bytes: 3064
import sys
from itertools import permutations
import math
n = int(input())
ls = []
for i in range(n):
    x, y = [int(i) for i in sys.stdin.readline().split()]
    ls.append((x, y))

_sum = 0
for candi in permutations(range(n)):
    for i in range(n-1):
        cur = ls[candi[i]]
        _next = ls[candi[i+1]]
        _sum += math.sqrt((cur[0] - _next[0]) ** 2 + (cur[1] - _next[1]) ** 2)
print(_sum / math.factorial(n))

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

#define io ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define ll long long
#define ull unsigned long long
#define pii pair<ll, ll>
#define piii pair<ll, pair<ll, ll>>
#define debug(x) cout<<#x<<" = "<<x<<endl

using namespace std;
const int N = 200005;
ll t, n, m, k, a, b, x, y, ans, arr[N];
ll mod = 998244353;
string s;
bool vis[N];

int main() {
    io;
    t = 1;
//    cin >> t;
    while (t--) {
        cin >> k >> a >> b;
        bool ans = false;
        for (int i = 1; i <= 10000; ++i) {
            ll cur = i * k;
            if (cur >= a && cur <= b)
                ans = true;
        }
        if (ans)
            cout << "OK" << endl;
        else
            cout << "NG" << endl;
    }
    return 0;
}
//  freopen("input.txt", "r", stdin);
//  freopen("output.txt", "w", stdout);


Measured memory_bytes: 3660
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
int x,y,z;
int main(){
	r(x);r(y);r(z);
	printf("%d\n",(x-z)/(y+z));
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin>>s;
	for (int i=0;i<s.size();i++)
	{
		if (s[i]=='?')   cout<<'D';
		else   cout<<s[i];
	}
	return 0;
} 

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

ll K, N;

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

  vector<ll> ans(N);
  if(K % 2 == 0) {
    ans[0] = K / 2;
    REP(i, 1, N) ans[i] = K;
  } else {
    REP(i, 0, N) ans[i] = (K + 1) / 2;
    ll p = 0;
    REP(i, 0, N / 2) {
      if(ans[N - 1 - p] == 0) p++;
      ans[N - 1 - p]--;
      if(p > 0 && ans[N - 1 - p] > 0) for(; p > 0; p--) ans[N - p] = K;
    }
    ans.erase(find(ans.begin(), ans.end(), 0), ans.end());
  }
  REP(i, 0, ans.size()) cout << ans[i] << (i + 1 != ans.size() ? " " : "\n");
}


Measured memory_bytes: 4608
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, M;
  cin >> N >> M;
  map<int, vector<int>> bs;
  F0R(i, N) {
    int a, b;
    cin >> a >> b;
    bs[a].push_back(b);
  }

  priority_queue<int, vector<int>, less<int>> qu;
  i64 result = 0;
  F0R(i, M) {
    //debug(i);
    for (auto e : bs[i + 1]) {
      qu.push(e);
      //debug(e);
    }
    if (qu.size()) {
      result += qu.top();
      //debug(qu.top());
      qu.pop();
    }
  }
  cout << result;
}
#endif


Measured memory_bytes: 14124
import java.util.*;
import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toMap;

public class Main {

    public static void main(String[] args) {

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

        int C = A + B + 1;

        int V = 0;
        int L = 0;
        boolean T = false;

        String S = Input.next();

        if (S.length() != C) {
            System.out.println("No");
        } else {
            if (S.charAt(A) == '-') {
                T = true;
            }
            for (int I = 0; I < S.length(); I++) {
                if (S.charAt(I) == '-') {
                    L++;
                } else {
                    V++;
                }
            }
            if (L == 1 && T) {
                System.out.println("Yes");

            } else {
                System.out.println("No");
            }
        }

    }
}


Measured memory_bytes: 23124
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <list>

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

int main() {
    int a,b;
    cin >> a >> b;
    if(a <= 8 and b <= 8) cout << "Yay!" << endl;
    else cout << ":(" << endl;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
#define REP(i,n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
int main() {

    int n,i;
    cin >> n >> i;
    
    cout << n-i+1 << endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int main(void){
    char number[1001];
    int sum;
    while (1) {
        int i = 0;
        sum = 0;
        scanf("%s", number);
        while (number[i] != '\0') {
            sum += number[i] - '0';
            i++;
        }
        if (sum == 0) break;
        cout << sum << endl;
    }
}

Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>
#include <map>
#include <set>
#include <deque>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int inf = 1<<30;
typedef pair<int, int> P;

struct Edge{ int to, id; };
vector<vector<Edge>> g;
vector<int> ans;

void dfs(int v, int c = -1, int p = -1) {
  int k = 1;
  rep(i, g[v].size()) {
    int u = g[v][i].to, ei = g[v][i].id;
    if(u == p) continue;
    if(k == c) ++k;
    ans[ei] = k; ++k;
    dfs(u, ans[ei], v);
  }
}

int main() {
  int n; cin >> n;
  g.resize(n);
  ans = vector<int>(n-1);
  rep(i, n-1) {
    int a, b; cin >> a >> b;
    a--, b--;
    g[a].push_back(Edge{b, i});
    g[b].push_back(Edge{a, i});
  }

  dfs(0);

  int mx = 0;
  rep(i, n) mx = max(mx, int(g[i].size()));
  cout << mx << endl;
  rep(i, n-1) {
    cout << ans[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 8320
/*
 * atcoder/abc129_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

int H, W;
bool G[2001][2001] = {0};
int L[2001][2001] = {0};
int R[2001][2001] = {0};
int U[2001][2001] = {0};
int D[2001][2001] = {0};

void solve() {
  cin >> H >> W;
  char c;
  loop(h,0,H) loop(w,0,W) {
    cin >> c;
    G[h][w] = c == '.';
  }

  loop(h,0,H) {
    for (int w=0; w<W;w++) {
      if (w==0) L[h][w] = G[h][w];
      else L[h][w] = G[h][w] ? L[h][w-1] + 1 : 0;
    }
    for (int w=W-1; w>=0; w--) {
      if (w==W-1) R[h][w] = G[h][w];
      else R[h][w] = G[h][w] ? R[h][w+1] + 1 : 0;
    }
  }

  loop(w,0,W) {
    for (int h=0; h<H; h++) {
      if (h==0) U[h][w] = G[h][w];
      else U[h][w] = G[h][w] ? U[h-1][w] + 1 : 0;
    }

    for (int h=H-1; h>=0; h--) {
      if (h==H-1) D[h][w] = G[h][w];
      else D[h][w] = G[h][w] ? D[h+1][w] + 1 : 0;
    }
  }

  int max_ = 0;
  loop(h,0,H) loop(w,0,W) {
    chmax(max_, L[h][w] + R[h][w] + U[h][w] + D[h][w] - 3);
  }
  cout << max_ << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 66688
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(v) v.begin(), v.end()
#define ll long long
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<long long>;
using vvll = vector<vll>;

//snippets:tmp,cl,cvl,cs,co,coy,con,cov
//export PATH=:~/.local/bin

int main(){
    ll k;
    cin >> k;
    string s;
    cin >> s;
    if(s.size()<=k){
        cout << s << endl;
    }else{
        rep(i,k){
            cout << s[i];
        }
        cout<<"..."<<endl;
    }
}

Measured memory_bytes: 3624
def main():
    N = int(input())
    A = list(map(int, input().split()))
    MOD = 10 ** 9 + 7
    ans = 1
    cnt = [0] * (N + 1)
    for i in range(N):
        if A[i] == 0:
            ans *= 3 - cnt[A[i]]
            cnt[A[i]] += 1
        else:
            ans *= cnt[A[i]-1] - cnt[A[i]]
            cnt[A[i]] += 1
        ans %= MOD

    print(ans)

    



if __name__ == "__main__":
    main()

Measured memory_bytes: 84760
import java.io.*;
import java.util.*;

public class Main {
    static ContestScanner in;
    static Writer out;
    public static void main(String[] args) {
        Main main = new Main();
        try {
            in = new ContestScanner();
            out = new Writer();
            main.solve();
            out.close();
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    void solve() throws IOException {
        String s = in.nextToken();
        if(s.length() < 4) {
            System.out.println("No");
        }else
        System.out.println(s.substring(0, 4).equals("YAKI") ? "Yes": "No");
    }

}

@SuppressWarnings("serial")
class MultiSet<T> extends HashMap<T, Long>{
    @Override public Long get(Object key){return containsKey(key)?super.get(key):0L;}
    public void add(T key,long v){put(key,get(key)+v);}
    public void add(T key){put(key,get(key)+1);}
    public void sub(T key){final long v=get(key);if(v==1)remove(key);else put(key,v-1);}
    public MultiSet<T> merge(MultiSet<T> set)
    {MultiSet<T>s,l;if(this.size()<set.size()){s=this;l=set;}else{s=set;l=this;}
        for(Entry<T,Long>e:s.entrySet())l.add(e.getKey(),e.getValue());return l;}
}

class Writer extends PrintWriter{
    public Writer(String filename)throws IOException
    {super(new BufferedWriter(new FileWriter(filename)));}
    public Writer()throws IOException{super(System.out);}
}
class ContestScanner implements Closeable{
    private BufferedReader in;private int c=-2;
    public ContestScanner()throws IOException
    {in=new BufferedReader(new InputStreamReader(System.in));}
    public ContestScanner(String filename)throws IOException
    {in=new BufferedReader(new InputStreamReader(new FileInputStream(filename)));}
    public String nextToken()throws IOException {
        StringBuilder sb=new StringBuilder();
        while((c=in.read())!=-1&&Character.isWhitespace(c));
        while(c!=-1&&!Character.isWhitespace(c)){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public String readLine()throws IOException{
        StringBuilder sb=new StringBuilder();if(c==-2)c=in.read();
        while(c!=-1&&c!='\n'&&c!='\r'){sb.append((char)c);c=in.read();}
        return sb.toString();
    }
    public long nextLong()throws IOException,NumberFormatException
    {return Long.parseLong(nextToken());}
    public int nextInt()throws NumberFormatException,IOException
    {return(int)nextLong();}
    public double nextDouble()throws NumberFormatException,IOException
    {return Double.parseDouble(nextToken());}
    public void close() throws IOException {in.close();}
}


Measured memory_bytes: 21460
import math
a,b=map(int, input().split())

if abs(a-b) == 1:
    c = math.factorial(a)%(10**9+7)
    d = math.factorial(b)%(10**9+7)
    print(c*d%(10**9+7))
if abs(a-b) == 0:
    c = math.factorial(a)%(10**9+7)
    d = math.factorial(b)%(10**9+7)
    print(c*d*2%(10**9+7))
if abs(a-b) >= 2:
    print(0)

Measured memory_bytes: 10116