akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.io.*;

public class Main {
	static final int like = 753;
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int n = sc.nextInt();
		List<String> list = new ArrayList<>();
		String s = sc.next();
		list.add(s);
		char last = s.charAt(s.length() - 1);	
		boolean flag = true;
		
		for(int i = 1; i < n; i ++) {
			s = sc.next();
			if (list.contains(s)) {
				flag = false;
				break;
			}
			char first = s.charAt(0);
			if (last != first) {
				flag = false;
				break;
			}
			last = s.charAt(s.length() - 1);
			list.add(s);
		}
		if (flag) out.println("Yes");
		else out.println("No");
		
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}



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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N, M;
	vector<int> v;
	cin >> N >> M;

	v.resize(N+1);
	for(int i = 0; i < M; i++){
		int a,b;
		cin >> a >> b;
		v[a]++;
		v[b]++;
	}

	for(int i = 1; i <= N; i++)
		cout << v[i] << endl;


	return 0;
}

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

/*
 * n[i][a][b][c]
 * 0: A
 * 1: G
 * 2: C
 * 3: T
 *
 */
int a = 0;
int g = 1;
int c = 2;
int t = 3;

string temp(int x) {
  if(x == a)
    return "a";
  if(x == g)
    return "g";
  if(x == c)
    return "c";
  if(x == t)
    return "t";
  return "";
}

/*
 * AGC 
 * A?GC 
 * GAC 
 * ACG 
 * AG?C
 */
long long we_like_agc(int n){
  long long mod = 1000000007;
  long long ans[100][4][4][4][4] = {{{{{0}}}}};

  if(n == 3)
    return 61;
  for(int j=0;j<4;j++) {
    for(int k=0;k<4;k++) {
      for(int l=0;l<4;l++) {
	for(int m=0;m<4;m++) {
	  ans[3][j][k][l][m] = 0;
	  if((j == a && k == g && l == c) || 
	     (j == g && k == a && l == c) || 
	     (j == a && k == c && l == g) || 
	     (j == a && k == g &&           m == c) || 
	     (          k == a && l == g && m == c) ||
	     (j == a           && l == g && m == c) || 
	     (          k == g && l == a && m == c) ||
	     (          k == a && l == c && m == g)){
	    continue;
	  }
	  ans[3][j][k][l][m] = 1;
	}
      }
    }
  }

  for(int i=4;i<n;i++) {
    for(int j=0;j<4;j++) {
      for(int k=0;k<4;k++) {
	for(int l=0;l<4;l++) {
	  for(int m=0;m<4;m++) {
	    // cout << i + 1 << "# " << temp(j) << ", " << temp(k) << ", " << temp(l) << ", " << temp(m) << "-> "; 
	    ans[i][j][k][l][m] = 0;
	  if((j == a && k == g && l == c) || 
	     (j == g && k == a && l == c) || 
	     (j == a && k == c && l == g) || 
	     (j == a && k == g &&           m == c) || 
	     (          k == a && l == g && m == c) ||
	     (j == a           && l == g && m == c) || 
	     (          k == g && l == a && m == c) ||
	     (          k == a && l == c && m == g)){
	    continue;
	  }
	  for(int o = 0;o<4;o++) {
	    ans[i][j][k][l][m] += ans[i-1][o][j][k][l];
	    ans[i][j][k][l][m] = ans[i][j][k][l][m] % mod;
	  }
	  // cout << ans[i][j][k][l][m] << endl;
	  }
	}
      }
    }
  }

  long long rtn = 0;
  for(int i=0;i<4;i++) {
    for(int j=0;j<4;j++) {
      for(int k=0;k<4;k++) {
	for(int l=0;l<4;l++) {
          // cout << n << "# " << temp(i) << ", " << temp(j) << ", " << temp(k) << ", " << temp(l) << "-> " << ans[n-1][i][j][k][l] << endl; 
	  rtn += ans[n-1][i][j][k][l];
	  rtn = rtn % mod;
	}
      }
    }
  }

  return rtn;
}
int main() {
  int n;
  cin >> n;
  cout << we_like_agc(n);
}

Measured memory_bytes: 384
import java.util.*

fun main(args:Array<String>){
    val (n,k) = readLine()!!.split(" ").map{it.toInt()}
    var ans : Double = 0.0
    for(i in 1 .. n){
        var t = 1.toDouble() / n
        var j = i
        while(j < k){
            t /= 2
            j *= 2
        }
        ans += t
    }
    println("%.20f".format(ans))
}


Measured memory_bytes: 37940
from collections import Counter
import sys

sys.setrecursionlimit(10 ** 6)

mod = 1000000007
inf = int(1e18)

dx = [0, 1, 0, -1]
dy = [1, 0, -1, 0]


def inverse(a):
    return pow(a, mod - 2, mod)


def usearch(x, a):
    lft = 0
    rgt = len(a) + 1
    while rgt - lft > 1:
        mid = (rgt + lft) // 2
        if a[mid] <= x:
            lft = mid
        else:
            rgt = mid
    return lft

n = int(input())
a = [int(i) - 1 for i in input().split()]
b = [[] for i in range(n)]
for i in range(n-1):
    b[a[i]].append(i)

#
# ans = [0] * n
#
#
# def solve(i):
#     if len(b[i]) == 0:
#         return 0
#     if ans[i] > 0:
#         return ans[i]
#     ret = 0
#     for k in b[i]:
#         ret += solve(k)
#     ans[i] = ret
#     return ret
#
# for i in range(n):
#     solve(i)

for i in b:
    print(len(i))



Measured memory_bytes: 113392
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
#define first fi;
#define second se;
void ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;

int main(){
  ll a,b,k;cin>>a>>b>>k;
  if(k<=a){
    cout<<a-k<<" "<<b<<endl;
  }
  
  else if(a<k && k<a+b){
    cout<<0<<" "<<a+b-k<<endl;
  }
  
  else{
    cout<<"0 0"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define ALL(v) v.begin(),v.end()
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 DEBUG_VLL(vec) for(int sz=0;sz<int(vec.size());sz++) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    V< V<int> > lcs(n + 1, V<int>(n + 1, 0));
    for (int i = n - 1; i >= 0; i--) {
        for (int j = n - 1; j >= 0; j--) {
            if (s[i] == s[j]) lcs[i][j] = lcs[i + 1][j + 1] + 1;
        }
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            chmax(ans, min(lcs[i][j], j - i));
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 101148
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define F first
#define S second
#define endl '\n'
#define deb(x) cout<<#x<<' '<<x<<endl;
#define pb push_back

/*
#ifdef IZI_KATKA
#define int __int64_t
#else
#define int __int64
#endif
*/

const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
    bool minus1 = false;
    long long result = 0;
    char ch;
    ch = getchar();
    while (true) {
        if (ch == '-') break;
        if (ch >= '0' && ch <= '9') break;
        ch = getchar();
    }
    if (ch == '-') minus1 = true; else result = ch-'0';
    while (true) {
        ch = getchar();
        if (ch < '0' || ch > '9') break;
        result = result*10 + (ch - '0');
    }
    if (minus1)
        return -result;
    else
        return result;
}

int used[MAXN];
int color[MAXN];

int col = 1;
vector <int> g[MAXN];
int a[MAXN];

void dfs(int v) {
	used[v] = col;
	color[a[v]] = col;
	for (int i : g[v]) {
		if (!used[i]) {
			dfs(i);
		}
	}			
}

int main() {
	#ifdef IZI_KATKA
	assert(freopen("input", "r", stdin));
    assert(freopen("output", "w", stdout));
    #endif
    int n = readInt(), m = readInt();
    for (int i = 1; i <= n; i++) {
    	a[i] = readInt();
    }
	for (int i = 1; i <= m; i++) {
		int l = readInt(), r = readInt();
		g[l].pb(r);
		g[r].pb(l);
	}
	for (int i = 1; i <= n; i++) {
		if (!used[i]) {
			dfs(i);
			col++;
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; i++) {  
		ans += color[i] == used[i];
	}
	cout << ans;
    return 0;
}

Measured memory_bytes: 34432
#pragma GCC optimize "-O3"
#pragma GCC target ("avx")
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define inf (1ll<<60)
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v),greater<int>())
#define SPEED ios::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(12)
signed gcd(int a, int b){return b?gcd(b,a%b):a;}
signed lcm(int a, int b){return a*b/gcd(a,b);}
//priority_queue<int, vi, greater<int> > que;//昇順

using namespace std;

const int mod=1e9+7;

signed main(){
    SPEED;
    int a,b,c;
    cin >> a >> b >> c;
    if(b-a==c-b)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
N = int(input())

if N <=9:
    print(N)
elif 10<=N<=99:
    print(9)
elif 100<=N <=999:
    print(9+N-99)
elif 1000<=N<=9999:
    print(9+900)
elif 10000<=N<=99999:
    print(9+900+N-9999)
else:
    print(90909)


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


int main() {
  ll N,T;cin>>N>>T;
  vector<ll> t(N);rep(i,N) cin>>t[i];
  
  ll ans=0;
  for(int i=0;i<=N-2;i++){
    if(t[i+1]-t[i]>T) ans+=T;
    else ans+=t[i+1]-t[i];
  }
  
  cout << ans+T << endl;
}


Measured memory_bytes: 4756
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<cstdlib>
#include<string>
#include<typeinfo>
#include<cassert>
#include<functional>
#include<algorithm>
#include<climits>
#include<map>

using namespace std;



int main(){

   vector<int> vec;

   int N;

   cin >> N;

   for(int i = 0;i < N;i++){
	   int a;
	   cin >> a;
       vec.push_back(a);
   }

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

   vec.erase(unique(vec.begin(),vec.end()),vec.end());

   cout << vec.size() << endl;

   return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include<bitset>

using namespace std;
#define loop(i,n) for(int i = 0; i < (n); ++i)
#define loops(i,f,n) for(int i = (f); i < (n); ++i)
#define INF 9999999
#define lint long long int
#define VEC vector<int>
#define VEC2 vector<vector<int>>

int count(int n)
{
	int ret = 0;
	while (n % 2 == 0)
	{
		ret++;
		n /= 2;
	}
	return ret;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = 0;
	loop(i, n)
	{
		int t;
		cin >> t;
		ans += count(t);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
 
YES = "Yes"  # type: str
NO = "No"  # type: str
 
def solve(N: int, A: int, B: int, C: int, D: int, S: str):
    ret = YES
    if '##' in S[A:C] or '##' in S[B:D]:
        ret = NO
    else:
        if D < C:
            #if S[B - 2:B] == '..' or S[B - 1:B + 1] == '..':
            if not '...' in S[B - 2:D + 1]:
                ret = NO
    print(ret)
    return
 
 
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    D = int(next(tokens))  # type: int
    S = next(tokens)  # type: str
    solve(N, A, B, C, D, S)
 
if __name__ == '__main__':
    main()

Measured memory_bytes: 41072
#include <iostream>
#include <vector>

using namespace std;

int main() {
    long long n;
    long long a, b, c, d, e;
    cin >> n;
    cin >> a >> b >> c >> d >> e;

    long long minMove = min({a, b, c, d, e});  // 3つ以上の値のminを取りたいときは配列風に

    long long ans = ((n + minMove - 1) / minMove) + 4;

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

Measured memory_bytes: 888
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  string s;
  cin >> s;
  if (s == "ARC") {
    cout << "ABC" << endl;
  } else {
    cout << "ARC" << endl;
  }
  return 0;
}


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

int main(){
 string S;
 cin >> S;
 
 if(S=="SUN"){
  cout << 7 << endl;
 }
  
 else if(S=="MON"){
  cout << 6 << endl;
 }
 
 else if(S=="TUE"){
  cout << 5 << endl;
 }

 else if(S=="WED"){
  cout << 4 << endl;
 }

  else if(S=="THU"){
  cout << 3 << endl;
 }

  else if(S=="FRI"){
  cout << 2 << endl;
 }

  else if(S=="SAT"){
  cout << 1 << endl;
 }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define qwq(x) cerr<<" #"<<#x<<" = "<<x<<endl;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
 
template<class T> inline void read(T &x){
	int f=0;x=0;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())f|=(ch=='-');
	for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
	if(f)x=-x;
}

const int N=2000005;
char s[N]; int S,ans;

int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	rep(i,1,n)
		if(s[i]=='S')S++,ans++;
		else if(S)S--,ans--;
		else ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    ArrayList<Integer> list = new ArrayList<Integer>();
    long MOD = (long)Math.pow(10, 9) + 7;
    for(int i = 2; i <= n; i++) {
      int p = 0;
      for(int j = 2; (j * j) <= i; j++) {
        if((i % j) == 0) p++;  
      }
      if(p == 0) list.add(i);
    }
    long ans = 1;
    for(int i = 0; i < list.size(); i++) {
      int g = list.get(i);
      int t = 0;
      int m = n;
      while(m > 0) {
        t += (m / g);
        m /= g;
      }
      ans = (ans * (long)(t + 1)) % MOD;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 35628
def main():
    n = int(input())
    R = [int(input()) for i in range(n)]
    
    min_r = R[0]
    ans = -float('inf')
    
    for r in R[1:]:
        ans = max(ans, r-min_r)
        min_r = min(min_r, r)
        
    print(ans)
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 15180
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int N, K;
string S;

int main() {
	cin >> N;
	cin >> S;
	cin >> K;
	for (int i = 0; i < N; i++) {
		if (S[i] != S[K - 1]) {
			S[i] = '*';
		}
	}

	cout << S << endl;
}

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

typedef long long ll;
using namespace std;


int main() {
  ll K;
  cin >> K;

  vector<ll> a;
  for (int i = 1; i <= 9; ++i) a.push_back(i);
  while(1) {
    if (K <= a.size()) {
      cout << a[K-1] << endl;
      return 0;
    }
    K -= a.size();
    vector<ll> old;
    swap(old, a);
    for (ll x : old) {
      for (int i = -1; i <= 1; ++i) {
        int d = x%10 + i;
        if (d < 0 || d > 9) continue;
        ll nx = x * 10 + d;
        a.push_back(nx);
      }
    }
  }

  return 0;
}

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

int getInt( string str ){
    int p = 1;
    int sum = 0;
    for ( int i = str.size()-1; i >= 0; i-- ){
	sum += (str[i]-'0')*p;
	p *=10;
    }
    return sum;
}

int main(){
    char ch;
    string digit = "";
    int sum = 0;
    while(scanf("%c", &ch) != EOF ){
	if ( '0' <= ch && ch <= '9' ) digit += ch;
	else {
	    if ( digit.size() > 0 ) sum += getInt(digit);
	    digit = "";
	}
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 0
use proconio::input;
use std::collections::HashSet;

fn main() {
    input! {
        n:i32,
        si:[String;n]
    }
    let mut words: HashSet<String> = HashSet::with_capacity(n as usize);
    for s in &si {
        words.insert(s.to_string());
    }
    println!("{}", words.len())
}


Measured memory_bytes: 27784
import java.util.*;
import java.io.*;
import java.math.*;
public class Main{
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		ou.println(Math.min(Integer.parseInt(sc.next()) * Integer.parseInt(sc.next()) , Integer.parseInt(sc.next())));
		ou.flush();
	}
}

Measured memory_bytes: 35688
#include<stdio.h>
int main(void){
	int n,t,flag,j,i;
	int cout=0;
	int A[100];
	scanf("%d\n",&n);
	for(t=0;t<n;t++){
		scanf("%d\n",&A[t]);
	}
	flag=1;
	i=0;
	while(flag){
		flag=0;
		for(j=n-1;j>=i+1;j--){
			if(A[j]<A[j-1]){
				int b;
				b=A[j];
				A[j]=A[j-1];
				A[j-1]=b;
				flag=1;
				cout++;
			}
		}
		i++;
	}
	for(t=0;t<n;t++){
		if(t==n-1){
			printf("%d\n",A[t]);
		}else{
			printf("%d ",A[t]);
		}
	}
	printf("%d\n",cout);
	
	return 0;
}


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

using namespace std;
typedef long long ll;

int p[100001], ace[100001];

int ancestor(int x) {
    return x == ace[x] ? x : ace[x] = ancestor(ace[x]);
}

int main(void) {
    int n, m, x, y, ax, ay;
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        scanf("%d", p+i);
        ace[i] = i;
    }

    for(int i=1; i<=m; i++) {
        scanf("%d%d", &x, &y);
        ax = ancestor(x); 
        ay = ancestor(y);
        if(ax != ay) ace[ax] = ace[ay];
    }

    int ans = 0;
    for(int i=1; i<=n; i++) {
        if(ancestor(i) == ancestor(p[i])) ans++;
    }

    return !printf("%d\n", ans);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define pb push_back
#define test ll t; cin>>t; while(t--)
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007LL
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
#define inc(i,a,n) for (ll i=a;i<n;i++)
#define dec(i,a,n) for (ll i=n-1;i>=a;i--)
int main()
{
  
    ll n;
    cin>>n;
    if(n%1000==0)
    {
       cout<<"0"<<endl;
    }
    else
    {
       cout<<1000-n%1000<<endl;
    }
    

  
   return 0;
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion

template<class T>
struct BIT {
    int n;
    vector<T> dat;

    //[1, n]
    BIT(int n): n(n), dat(n + 1) {}

    void init(int _n) {
        n = _n;
        dat.assign(_n);
    }

    //[1, i]
    T sum(int i) const {
        T s = 0;
        while (i > 0) {
            s += dat[i];
            i -= i & -i;
        }
        return s;
    }

    //[l, r]
    T sum(int l, int r) const {
        return sum(r) - sum(l - 1);
    }

    //1-indexed
    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }
};

struct Query {
    int l, r, idx;
    bool operator <(const Query &q) { return r < q.r; }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    //cin >> c;
    rep(i, n) scanf("%d", &c[i]);

    vector<Query> querys(q);
    rep(i, q) {
        int l, r;
        //cin >> l >> r;
        scanf("%d %d", &l, &r);
        querys[i] = Query{l, r, i};
    }

    sort(querys.begin(), querys.end());
    
    BIT<int> bit(n);
    vector<int> last(n + 1, -1);
    vector<int> ans(q);

    int p = 0;
    rep(i, q) {
        auto [l, r, idx] = querys[i];
        while (p < n && p < r) {
            bit.add(p + 1, 1);
            if (last[c[p]] != -1) bit.add(last[c[p]] + 1, -1);
            last[c[p]] = p;
            p++;
        }

        ans[idx] = bit.sum(l, r);
    }

    //print(ans, "\n");
    rep(i, q) printf("%d\n", ans[i]);
}

Measured memory_bytes: 17372
'use strict'

function Main(input) {
  const inputs = input.split('\n');
  const n = inputs[0];
  const k = inputs[1];
  const balls = inputs[2].split(' ').map(n => parseInt(n, 10)).sort((a, b) => a-b);
  
  let sum = 0;
  balls.map(b => {
    const dist = Math.min(b, k - b);
    sum += dist * 2;
  });
  
  console.log(sum);
}

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


Measured memory_bytes: 11980
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

ll eval(ll n) {
	if(n<=0) return 0;
	ll ret=0;
	for (ll cur=ll(n/4)*4; cur<=n; cur++)
		ret^=cur;
	return ret;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	ll A,B; cin>>A>>B;
	cout<<(eval(B)^eval(A-1))<<"\n";
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  
  int n,abc=0,i;
  char s[50];
  
  scanf("%d",&n);
  scanf("%s",s);
  
  for(i=0; i<n-2; i++) if(s[i]=='A') if(s[i+1]=='B') if(s[i+2]=='C') abc++;
    
  printf("%d",abc); 
    
    return 0;  
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a); i<int(b); ++i)
#define RFOR(i,a,b) for(int i=(b)-1; i>=int(a); --i)
#define rep(i,n) FOR(i,0,n)
#define rep1(i,n) FOR(i,1,int(n)+1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
#define al(d) d.begin(),d.end()

template <typename T>
void putv(vector<T>& V){
	// cout << "The elements in the vector are: " << endl;
	for(auto x: V)
		cout << x << " ";
	cout << endl;
}
template <class T>
vector<T> getv(int n){
	vector<T> vec;
	rep(i,n){
		T input;
		cin >> input;
		vec.emplace_back(input);
	}
	return vec;
}
int digit(unsigned long long n);
int main(){
	long long N;
	cin >> N;
// cout << N << endl;
	long long sqrt = (long long)pow(N,0.5);
// cout << sqrt;
	for(long long i=sqrt; i>0; --i)
		if(N%i==0){
// cout <<i << ","<< N/i<< endl;
			cout << digit(N/i) << endl;
			break;
		}
	return 0;
}

int digit(unsigned long long n){
	if(n == 0) return 1;
	unsigned int cntr = 0;
	while(n!=0){
		n /= 10;
		cntr++;
	}
	return cntr;
}

Measured memory_bytes: 384
#include <iostream>

using namespace std;
long long N, W;
long long w[1005];
long long v[1005];
long long F[1005][100005];


int main()
{
    cin>>N>>W;
    for(long long i=1; i<=N; i++)
    {
        cin>>w[i]>>v[i];
    }
    for(int i=1; i<=N; i++)
    {
        for(int j=1; j<=W; j++)
        {
            if(j>=w[i])
            F[i][j]=max(F[i-1][j], F[i-1][j-w[i]]+v[i]);
            else F[i][j]=F[i-1][j];
        }
    }
    cout<<F[N][W];
    return 0;
}


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

int main(){
	int n;
	cin >> n;
	
	int a[n][2];
	for(int i=0; i<n; i++) cin >> a[i][0] >> a[i][1];
	
	for(int i=0; i+2<n; i++){
		if(a[i][0]==a[i][1] && a[i+1][0]==a[i+1][1] && a[i+2][0]==a[i+2][1]){
			cout << "Yes";
			return 0;
		}
	}
	cout << "No";
	return 0;
}

Measured memory_bytes: 3644
import math
import sys
import itertools

N = int(input())
xy = [list(map(int,input().split())) for _ in range(N)]


ans = 0
fact = 1
for i in range(N):
    fact *= (i+1)

for x in itertools.permutations(range(N)):
    for i in range(N-1):
        ans += math.sqrt((xy[x[i]][0]-xy[x[i+1]][0])**2+(xy[x[i]][1]-xy[x[i+1]][1])**2)

ans /= fact
print(ans)
        


Measured memory_bytes: 3064
#include <stdio.h>
int main(void){
	char e[51][51];
	int i, j,a,b,c=0;
	scanf("%d %d", &a, &b);
	for (i = 0; i < a; i++){
		for (j = 0; j < b+1; j++){
			scanf("%c", &e[i][j]);
		}
	}
	for (i = 0; i < a; i++){
		for (j = 0; j < b+1; j++){
			if (e[i][j] == '#'&&e[i - 1][j] != '#'&&e[i + 1][j] != '#'&&e[i][j + 1] != '#'&&e[i][j - 1] != '#'){
				c++;
			}
		}
	}
	if (c == 0){
		printf("Yes");
	}
	else{
		printf("No");
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;


int main() {
string s;
cin >> s;
if(s=="SUN") {
  cout << "7" << endl;
} else if(s=="MON") {
  cout << "6" << endl;
} else if(s=="TUE") {
  cout << "5" << endl;
} else if(s=="WED") {
  cout << "4" << endl;
} else if(s=="THU") {
  cout << "3" << endl;
} else if(s=="FRI") {
  cout << "2" << endl;
} else {
  cout << "1" << endl;
}
return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int[] an = new int[5];
        an[0] = sc.nextInt();
        an[1] = sc.nextInt();
        an[2] = sc.nextInt();
        an[3] = sc.nextInt();
        an[4] = sc.nextInt();
        int k = sc.nextInt();

        for(int i = 0;i < 5;i++){
            for(int j = i+1;j < 5;j++){
                if(Math.abs(an[i]-an[j]) > k){
                    System.out.println(":(");
                    System.exit(0);
                }
            }
        }
        System.out.println("Yay!");
    }
}


Measured memory_bytes: 21844
/*BISMILLAH
THE WHITE WOLF
NO DREAM IS TOO BIG AND NO DREAMER IS TOO SMALL*/

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<long long> vll;
typedef vector<int> vi;

#define io ios_base::sync_with_stdio(false)
#define pb push_back
#define eb emplace_back
#define mod   998244353
#define PI 2*acos(0.0)
#define dbg(a) cout<<#a<<" ->->->-> "<<a<<"\n"
int dirx[] = {1, -1,0, 0}, diry[] = {0, 0, 1, -1};

ll bigmod(ll x, ll p)
{
    ll res = 1;
    while(p)
    {
        if(p&1)
            res = (res*x)%mod;
        x = (x*x)%mod;
        p >>= 1;
    }
    return res;
}

//=============================================ASIFAZAD==============================================//

int32_t main()
{
    io;
    int n, w;
    cin>>n>>w;
    vi wg(n), val(n);

    for(int i = 0; i< n;i++)
        cin>>wg[i] >> val[i];

    ll dp[100009];
    for(int i = 0; i< 100009; i++)
        dp[i] = INT_MIN;
    dp[0] = 0;

    for(int i = 0; i< n;i++)
        for(int j = w - wg[i]; j>= 0;j--)
            dp[j + wg[i]] = max(dp[j+wg[i]], dp[j] + val[i]);

    ll ans = 0;
    for(int i = 0; i<= w; i++)
        ans = max(ans, dp[i]);

    cout<<ans;
    return 0;
}


Measured memory_bytes: 4432
/*
    Author : DemonStar
*/

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(x) x.begin(), x.end()
#define loop(i, n) for(ll i = 0; i < n; i++)
#define pl pair<ll, ll>
#define vl vector<ll>
#define endl '\n'
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}

#ifdef LOCAL
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};


template <typename T, typename TT>
ostream &operator<<(ostream &os, const pair<T, TT> &t) {
    return os << t.first << " " << t.second;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &t) {
    for (auto &i : t) os << i << " ";
    return os;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (T &t : v) is >> t;
    return is;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, vector<pair<T1, T2>> &v) {
    for (pair<T1, T2> &t : v) is >> t.first >> t.second;
    return is;
}

const ll mod = 1e9 + 7;

int main()
{

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll n, ans = 0;
    cin >> n;
    for (ll i = 1; i <= n; i++) {
        ll num = n / i;
        ans += num * (2 * i + (num - 1) * i) / 2;
    }

    cout << ans << endl;


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s";
#endif

    return 0;
}

Measured memory_bytes: 3640
def resolve():
    N, K = map(int, input().split())

    # Kの倍数である数値の個数を数える
    a = 0
    for i in range(1, N + 1):
        if i % K == 0:
            a += 1

    # 余りがKの半分となる数値の個数を数える
    b = 0
    for i in range(1, N + 1):
        if i % K == K // 2:
            b += 1

    # 全ての要素がKの倍数の場合を足す
    ans = a * a * a
    if K % 2 == 0:
        # 全ての要素がK/2の場合を足す
        ans += b * b * b

    print(ans)


if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9168
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		String shuffled_card = ""; // シャッフル後のカードの状態
		int m = 0; // シャッフル回数
		int h = 0; // 下からとる枚数
		int MAX_DATA = 10;
		int NUMBER_OF_DATA = 0;
		String n = ""; // 入力されたカードの山
		boolean judge_m = true; // シャッフル回数が条件を満たしているかを示す変数
		boolean judge_n = true; // 入力されたn枚のカードが条件を満たしているかを示す変数
		String[] output = new String[MAX_DATA];

		out: for (int i = 0; i < MAX_DATA; i++) {

			// 始:カードの入力とチェック
			n = sc.next();
			shuffled_card = n;
			if (n.equals("-")) {
				break out;
			}
			NUMBER_OF_DATA++;
			if (n.length() < 1 || n.length() > 200) {
				judge_n = false;
				break out;
			}
			// 終:カードの入力とチェック

			// 始:シャッフル回数mの入力とチェック
			m = sc.nextInt();

			if (m < 1 && m > 100) {
				judge_m = false;
				break out;

			}
			// 終:シャッフル回数mの入力とチェック

			for (int j = 0; j < m; j++) {
				h = sc.nextInt();
				shuffled_card = shuffled_card.substring(h,
						shuffled_card.length())
						+ shuffled_card.substring(0, h);

			}
			output[i] = shuffled_card;
		}// out:for文ここまで

		if (judge_m == true && judge_n == true) {
			for (int k = 0; k < NUMBER_OF_DATA; k++) {
				System.out.println(output[k]);

			}
		}
	}
}



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

int main(void)
{
    int N, D;
    int i, j, k;
    double tmp;
    int count = 0;
    int X[11][11];

    scanf("%d %d",&N,&D);

    for(i=0; i<N; i++){
        for(j=0; j<D; j++){
            scanf("%d",&X[i][j]);
        }
    }

    for(i=0; i<N-1; i++){
        for(k=i+1; k<N; k++){
            
            tmp=0;
            //距離を求める
            for(j=0; j<D; j++){
                tmp += (X[i][j]-X[k][j])*(X[i][j]-X[k][j]);
                //printf("tmp2 = %f\n",tmp);
            }
            tmp = sqrt(tmp);
            //printf("i=%d, j=%d, k=%d, tmp2=%f, ceil(tmp1) = %f, tmp1 = %f\n",i,j,k,tmp2,ceil(tmp1),tmp1);
            if(ceil(tmp) == tmp) count++;

        }
    }

    printf("%d\n",count);
    
    return 0;
}

Measured memory_bytes: 128
from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
a = stdin.readline().rstrip().split()
b = [int(s) for s in a]
res = 0
for el in b:
    res += el
if res >= 22:
    print('bust')
else:
    print('win')


Measured memory_bytes: 3700
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>

int main(){
    
    size_t n, k;
    std::cin >> n >> k;

    std::vector<size_t> l(n);

    for(auto&& e : l){
        std::cin >> e;
    }

    std::sort(l.begin(), l.end(), std::greater<size_t>{});

    std::cout << std::accumulate(l.begin(), l.begin() + k, 0) << std::endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define INF 1000000000
int main(){
cin.tie(0);
ios::sync_with_stdio(false);

	int N,M;
	cin>>N>>M;
	vector<int>A(N);
	REP(i,N)A[i]=0;
	//int j=0,k=0;
	REP(i,M){
		int a,b;
		cin>>a>>b;
		if(b==N){
			A[a-1]++;
		}
		if(a==1){
			A[b-1]++;
		}
	}
	//REP(x,j)cout<<A[x]<<endl;
	//REP(x,k)cout<<B[x]<<endl;
	REP(i,N){
		if(A[i]==2){
			cout<<"POSSIBLE"<<endl;
			return 0;
		}
	}
	cout<<"IMPOSSIBLE"<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int main(void){
	int cases;
	
	cin >> cases;
	while(cases--){
		int n;
		cin >> n;
		int a[n];
		int down = 0, up=0;
		for(int i=0;i<n;i++) cin >> a[i];
		for(int i=1;i<n;i++){
			if(a[i] > a[i-1]){
				up = max(up, a[i] - a[i-1]);
			}else{
				down = max(down, a[i-1] - a[i]);
			}
		}
		cout << up << " " << down << endl;
	}
}

Measured memory_bytes: 0
package main

import (
	"fmt"
)

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	var sum int
	as := make([]int, n)
	for i := range as {
		fmt.Scan(&as[i])
		sum += as[i]
	}
	var cnt int
	for i := range as {
		if as[i]*4*m >= sum {
			cnt++
		}
	}
	if cnt >= m {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=5005;
const ll INF=1LL<<60;
ll dp[MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    ll A,B;cin>>A>>B;
    vector<int> S(N);
    for(int i=0;i<N;i++) cin>>S[i];
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            dp[i][j]=INF;
        }
    }
    dp[0][0]=0;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=N;j++){
            if(j<S[i]){
                dp[i+1][S[i]]=min(dp[i+1][S[i]],dp[i][j]);
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+A);
            }else{
                dp[i+1][j]=min(dp[i+1][j],dp[i][j]+B);
            }
        }
    }
    
    ll ans=INF;
    
    for(int i=1;i<=N;i++) ans=min(ans,dp[N][i]);
    
    cout<<ans<<endl;
}


Measured memory_bytes: 195840
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string s; cin >> s;
    string t; cin >> t;
    const int N = 26;
    vector<int> sp(N,-1);
    vector<int> tp(N,-1);
    auto apos = [](char c) {return c - 'a';};

    int si = 0, ti = 0;
    bool ans = true;
    REP(i,s.size()) {
        int sc = apos(s[i]);
        int tc = apos(t[i]);
        if (sp[sc] == -1) sp[sc] = si++;
        if (tp[tc] == -1) tp[tc] = ti++;
        if (sp[sc] !=tp[tc]) {
            ans = false;
            break;
        }
    }

    ATYN(ans)

    return 0;
}

Measured memory_bytes: 916
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int n;
int[][] adj;

void main() {
    scan(n);
    adj = new int[][](n, 0);

    int ai, bi;

    foreach (i ; 0 .. n - 1) {
        scan(ai, bi);
        ai--; bi--;
        adj[ai] ~= bi;
        adj[bi] ~= ai;
    }

    auto d = new int[](n);
    auto p = new int[](n);

    void dfs(int u, int par, int dep) {
        d[u] = dep;
        p[u] = par;

        foreach (v ; adj[u]) {
            if (v != par) {
                dfs(v, u, dep + 1);
            }
        }
    }

    dfs(0, 0, 0);

    int x = (d[n - 1] - 1) / 2;
    int pos = n - 1;

    while (x--) {
        pos = p[pos];
    }

    int dfs2(int u) {
        int res = 1;

        foreach (v ; adj[u]) {
            if (v != p[u]) {
                res += dfs2(v);
            }
        }

        return res;
    }

    int cnt = dfs2(pos);

    if (cnt*2 >= n) {
        writeln("Snuke");
    }
    else {
        writeln("Fennec");
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

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

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> a(n+10,1);
  const long long MOD = 1000000007;
  for (int i = 0; i < m; i++)
  {
    int x;
    cin >> x;
    a[x] = 0;
  }

  vector<long long> dp(n+5);
  dp[0]=1;
  dp[1]=a[1];
  for (int i = 2; i <= n; i++)
  {
    if(a[i]) dp[i] = dp[i-1]+dp[i-2];
    else dp[i]=0;
    dp[i]%=MOD;
  }
  cout << dp[n] << endl;  
}

Measured memory_bytes: 1408
import numpy as np

d = int(input())
c = list(map(int, input().split()))
c_sum = sum(c)
s = [[] for _ in range(d)]
for i in range(d):
  s[i] = list(map(int, input().split()))
  
last = [0 for _ in range(26)]
plan = [-1 for _ in range(d)]

def loss(today):
  sum = 0
  for i in range(26):
    sum += c[i-1] * (today - last[i-1])
  return sum
  
  
v = 0
for today in range(1, d+1):
  t = np.argmax([s[today-1][i] + c[i]*(today - last[i-1]) for i in range(26)])
  t += 1
  last[t-1] = today
  plan[today-1] = t
  print(t)

Measured memory_bytes: 27492
#include<iostream>

using namespace std;

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

  while(n != 0 || x != 0)
    {
      int cnt = 0;
      for ( int i = 1; i < n-1; i++ )
        {
          for ( int j = i+1; j < n; j++)
            {
              for ( int k = j+1; k <= n; k++ )
                {
                  if ( i + j + k == x ) cnt++;
                }
            }
        }
      cout << cnt << endl;
      cin >> n >> x;
    }
  return 0;
}

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

#define N 200020
typedef long long ll;

int n, L, a[N];

struct data {
	int le, ri, lv, rv;
	data(int le = 0, int ri = 0, int lv = 0, int rv = 0):le(le), ri(ri), lv(lv), rv(rv) {}
	bool operator < (const data &a) const {return le < a.le;}
};

typedef pair<int, int>  pii;
set<data> S;

ll calc(vector<data> &v) {
	ll sum = 0;
	ll rlt = 0;
	for (int i = 0; i < v.size(); i ++) {
		sum += v[i].lv;
		if (i + L <= v.size()) rlt += sum * v[i+L-1].rv;
	}
	return rlt;
}

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
	cin>>n>>L;
	vector<pii> pos;
	for (int i = 1; i <= n; i ++) {
		cin>>a[i];
		pos.emplace_back(a[i], i);
	}
	sort(pos.begin(), pos.end());
	int now = 1;
	int cur = 0;
	ll ans = n;
	while (1) {
		if (S.empty()) {
			if (cur >= pos.size()) break;
			now = pos[cur].first;
		}
        while (cur < pos.size() && pos[cur].first == now) {
			S.insert(data(pos[cur].second, pos[cur].second, 1, 1));
			cur ++;
        }
        vector<data> all;
        while (!S.empty()) {
			set<data>::iterator it = S.begin();
			vector<data> tmp = {*it};
			S.erase(*it);
			while (!S.empty() && S.begin()->le == tmp.back().ri + 1) {
				tmp.push_back(*S.begin());
				S.erase(*S.begin());
			}
			if (tmp.size() >= L) {
				ans += calc(tmp);
				int c = tmp.size() / L;
				vector<data> nw = tmp;
				nw.resize(c);
				for (int i = 0; i < c; i ++) {
					nw[i].le = tmp[0].le + i;
					if (i < c - 1) nw[i].ri = nw[i].le;
					else nw[i].ri = tmp.back().ri;
					nw[i].lv = nw[i].rv = 0;
				}
				for (int i = 0; i < tmp.size(); i ++) {
					int l = i + 1, r = tmp.size() - i;
					if (l >= L) nw[l/L-1].rv += tmp[i].rv;
					if (r >= L) nw[c-r/L].lv += tmp[i].lv;
				}
				ans -= calc(nw);
				for (auto q:nw) all.push_back(q);
			}
        }
		for (auto q:all) S.insert(q);
        now ++;
	}
	cout<<ans;
}


Measured memory_bytes: 13424