akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll v[100009], l[100009], r[100009];

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

    l[0] = v[0];
    for(int i = 1; i < n; ++i)
        l[i] = __gcd(v[i], l[i-1]);

    r[n-1] = v[n-1];
    for(int i = n-2; i >= 0; --i)
        r[i] = __gcd(v[i], r[i+1]);

    ll ans = r[0];
    for(int i = 1; i+1 < n; ++i) {
        //cerr << "AT " << i << " " << __gcd(l[i-1], r[i+1]) << endl;
        ans = max(ans, __gcd(l[i-1], r[i+1]));
    }
    ans = max(ans, max(r[1], l[n-2]));

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

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

int main(void){
  int N,a,b; long long sum=0; cin >> N;
  vector<int> Q(100001,0);
  while(N--){cin >> a; sum+=a; ++Q[a];}
  cin >> N;
  while(N--){cin >> a >> b; sum+=(b-a)*Q[a]; Q[b]+=Q[a]; Q[a]=0; cout << sum << endl;}
  return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    int n; cin >> n;
    string s; cin >> s;

    int ans = 0;
    int cnt = 0;

    for (int i = 0; i < n; ++i) {
        if (s[i] == 'I') {
            ++cnt;
        }

        if (s[i] == 'D') {
            --cnt;
        }

        ans = max(ans, cnt);
    }

    cout << ans << endl;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

#define Sort(x) sort(x.begin(),x.end())
#define Reverse(x) reverse(x.begin(),x.end())
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))

constexpr ll MOD = 1e9+7;
// constexpr int INF = 1<<25;
// constexpr ll  INF = 1LL<<50;

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T checkmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T checkmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

// a = (a+b)%MOD;
void addmod(ll& a, ll b) {
  a = (a+b)%MOD;
}

// Forward declaration
template <typename T>
void dumpContents(const T& v, const string& msg="");

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========
// k 0-indexed
/*
ll solve(const vll& A, const vll& B, int k) {
  vll ret;
  ret.reserve(k);

  for (int i=0; i<int(A.size()); i++) {
    int j = k -1;
    ret.emplace_back(A[i]+B[i]);
  }

  Sort(ret);
}
*/

int main(int argc, char** argv) {
  int X, Y, Z, K;
  cin >> X >> Y >> Z >> K;
  vll A(X);
  vll B(Y);
  vll C(Z);
  for (int i=0; i<X; i++) {
    cin >> A[i];
  }
  for (int i=0; i<Y; i++) {
    cin >> B[i];
  }
  for (int i=0; i<Z; i++) {
    cin >> C[i];
  }

  vll D;
  D.reserve(Y*Z);
  for (int i=0; i<Y; i++) {
    for (int j=0; j<Z; j++) {
      D.emplace_back(B[i]+C[j]);
    }
  }

  Sort(A);
  Reverse(A);
  Sort(D);
  Reverse(D);

  // AとDとを比べればよい
  vll ret;
  ret.reserve(1000*1000);

  for (int i=0; i<int(A.size()); i++) {
    for (int j=0; j<int(D.size()); j++) {
      if (i+j>=K) break;
      ret.emplace_back(A[i]+D[j]);
    }
  }
  Sort(ret);
  Reverse(ret);

  for (int i=0; i<K; i++) {
    cout << ret[i] << endl;
  }


  return 0;
}


Measured memory_bytes: 41336
input_line = gets.chomp.split(" ")
n = input_line[0].to_i
d = input_line[1].to_i
result = 0
mat = Array.new(n).map{Array.new(d,0)}
for i in 0 .. n-1
  input_line = gets.chomp.split(" ")
  for j in 0 .. d-1
    mat[i][j] = input_line[j].to_i
  end
  #p mat
end
#p mat
for i in 0 .. n-1
  for j in i+1..n-1
    dist = 0
    for k in 0 .. d-1
      dist += (mat[i][k] - mat[j][k])**2
    end
    dist = Math.sqrt(dist)
    if dist % 1 == 0 then
      #puts "yes"
      result += 1
    end
    #puts dist
  end
end
puts result

Measured memory_bytes: 1788
N = int(input())
As = list(map(int, input().split()))
E = 10 ** 9 + 7

dp = [(1, [0, 0, 0])]
for i in range(N):
    p = dp[i][0]

    cc = 0
    sw = False
    cp = [dp[i][1][0], dp[i][1][1], dp[i][1][2]]
    for c in range(3):
        if As[i] == dp[i][1][c]:
            cc += 1
            if not sw:
                cp[c] += 1
                sw = True
    p = (p * cc) % E
    dp.append((p, cp))
print(dp[N][0])

Measured memory_bytes: 67980
#include <cstdio>
#include <cstring>
char s[105];
int main()
{
 scanf("%s",s+1);
 int len=strlen(s+1),flag=true;
 for(int i=1;i<=len;i++)
  if(i%2)
  {
   if(s[i]=='L')flag=false;
  }
  else
  {
   if(s[i]=='R')flag=false;
  }
 puts(flag?"Yes":"No");
 return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;

bool checkStackPermutation(int ip[], int op[], int n) 
{ 
    // Input queue 
    queue<int> input; 
    for (int i=0;i<n;i++) 
        input.push(ip[i]); 
  
    // output queue 
    queue<int> output; 
    for (int i=0;i<n;i++) 
        output.push(op[i]); 
  
    // stack to be used for permutation 
    stack <int> tempStack; 
    while (!input.empty()) 
    { 
        int ele = input.front(); 
        input.pop(); 
        if (ele == output.front()) 
        { 
            output.pop(); 
            while (!tempStack.empty()) 
            { 
                if (tempStack.top() == output.front()) 
                { 
                    tempStack.pop(); 
                    output.pop(); 
                } 
                else
                    break; 
            } 
        } 
        else
            tempStack.push(ele); 
    } 
  
    // If after processing, both input queue and 
    // stack are empty then the input queue is 
    // permutable otherwise not. 
    return (input.empty()&&tempStack.empty()); 
} 

int main()
{
  fastio();

 
 int T;
T=1;
//cin>>T;
while(T--)
{
ll int a,b,c,d,a1,a2;
cin>>a>>b>>c>>d;

if(c%b==0)
  a1=c/b;
else
  a1=c/b+1;
if(a%d==0)
{
  a2=a/d;
}
else
a2=a/d+1;

//cout<<a1<<a2<<endl;
if(a1<=a2)
{
  cout<<"Yes"<<endl;
}
else
cout<<"No"<<endl;

}

    return 0;
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define LEN(s)      (string(s)).length()
#define NPOS        string::npos
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<class T>string join(const vector<T>& v,string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(LEN(d));}

template<class T>ostream& operator<<(ostream& s,const vector<T>& v)
{s<<"{";if(SZ(v))s<<join(v,", ");s<<"}";return s;}

template<class T>bool contain(const string& s,const T& v)
{return s.find(v)!=NPOS;}

template<class T,class U>string& replace(string& s,const T& f,const U& t)
{for(auto p=s.find(f);p!=NPOS;p=s.find(f,p+LEN(t)))s.replace(p,LEN(f),t);}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll A, B; cin >> A >> B;
    
    if (A == 1) A += 13;
    if (B == 1) B += 13;
    
    if (A > B) cout << "Alice" << endl;
    if (A < B) cout << "Bob" << endl;
    if (A == B) cout << "Draw" << 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++)
using ll = long long;

int main() {
int n,d;
cin >> n >> d;
vector<vector<int>> a(n,vector<int>(d));
rep(i,n){
  rep(j,d) cin >> a.at(i).at(j);
}
int ans = 0;
rep(i,n){
  rep(j,i){
    int dis = 0;
    rep(k,d){
      dis += (a.at(i).at(k) - a.at(j).at(k))*(a.at(i).at(k) - a.at(j).at(k));
    }
    double s = sqrt(dis);
    int t = s/1;
    if(t == s) ans++;
  }
}
cout << ans << endl;
}
  


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

int main() {
    long long n;
    cin >> n;
    long long d[n];
    long long e[n];
    for(int i=0;i<n;i++){
        d[i]=0;
        e[i]=0;
    }
    long long a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
        if(i+a[i]<=n-1) d[i+a[i]]++;
        if(i-a[i]>=0) e[i-a[i]]++;
    }
    long long ans=0;
    for(int i=0;i<n;i++) ans+=d[i]*e[i];
    cout << ans << endl;
}

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

using namespace std;

#define pb push_back
#define ll long long
#define MX 1000009

bool marked[MX+1];

ll gcd(ll a, ll b)
{
    return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    return a * ( b / gcd(a, b));
}

void sieve()
{
    marked[0] = true;
    marked[1] = true;
    for(int i = 4; i <= MX; i += 2)
        marked[i] = true;
    for(ll i = 3; i * i <= MX; i += 2)
    {
        for(ll j = i * i; j <= MX; j += i)
             marked[j] = true;
    }
}

int main()
{
    //cout << "Hello world!!" << endl;
      string str;
      cin >> str;
      int cnt = 0;
      for(int i = 1; i < str.length(); i++)
          if( str[i] == str[i-1]  )
         {
            cnt++;
            if( str[i] =='0')str[i]='1';
            else str[i] = '0';
         }
     cout << cnt <<  endl;
    return 0;
}


Measured memory_bytes: 512
#ifdef LOCAL
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
#else
#include <bits/stdc++.h>
#endif
using namespace std ;

typedef long long ll ;
#define rep(i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	int N;
	
	cin >> N;

	int n = (N & 1) ? (N >> 1) + 1 : (N>>1);

	cout << (float)n / N << endl;

	
	return 0;
}


Measured memory_bytes: 256
A1 = [int(x) for x in input().split()]
A2 = [int(x) for x in input().split()]
A3 = [int(x) for x in input().split()]
A = [A1, A2, A3]
B = [[False] * 3 for i in range(3)]
N = int(input())
b = [0]*N
for i in range(N):
  j = int(input())
  for m in range(3):
    for n in range(3):
        if A[m][n] == j:
          B[m][n] = True
def check():
    for i in range(3):
      if sum(B[i]) == 3:
        return "Yes"
    for j in range(3):
      if sum([B[k][j] for k in range(3)]) == 3:
        return "Yes"
    if B[0][0] + B[1][1] + B[2][2] == 3 or B[0][2] + B[1][1] + B[2][0] == 3:
      return "Yes"
    return "No"
 
print(check())

Measured memory_bytes: 3064
import itertools

def judge(board):
  ret=True
  pos=[]
  for i in range(8):
    for j in range(8):
      if board[i][j]=='Q':
        pos.append((i,j))
  for i in range(8):
    tx1,ty1=pos[i]
    for j in range(8):
      tx2,ty2=pos[j]
      if i==j:
        continue
      if ty1==ty2 or tx1==tx2 or abs(ty1-ty2)==abs(tx1-tx2):
        ret=False
  return ret

k=int(input())
board=[['.']*8 for _ in range(8)]
pos1=[0,1,2,3,4,5,6,7]
pos2=[0,1,2,3,4,5,6,7]
for _ in range(k):
  a,b=map(int,input().split())
  board[a][b]='Q'
  pos1.remove(b)
  pos2.remove(a)
for tpos in itertools.permutations(pos1):
  for i in range(len(tpos)):
    board[pos2[i]][tpos[i]]='Q'
  if judge(board)==True:
    break
  for i in range(len(tpos)):
    board[pos2[i]][tpos[i]]='.'
for i in range(8):
  print(''.join(board[i]))


Measured memory_bytes: 5656
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	static final boolean debugMode = false;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = readInt(sc);
		int m = readInt(sc);

		int c = 0;
		for (int i = 0; i < m; i++) {
			c += readInt(sc);
		}

		System.out.println(n - c >= 0 ? n - c : -1);

	}

	// con.) a >= b
	static int gcm(int a, int b) {
		while (true) {
			if (b == 0)
				break;

			int mod = a % b;
			a = b;
			b = mod;
		}
		return a;
	}

	// con.) a >= b
	static int lcm(int a, int b) {
		return a * b / gcm(a, b);
	}

	static int readInt(Scanner sc) {
		return Integer.parseInt(sc.next());
	}

	static Long readLong(Scanner sc) {
		return Long.parseLong(sc.next());
	}

	static void log(String s) {
		if (debugMode) {
			System.out.println(s);
		}
		return;
	}
}

class Pair {
	private int x;
	private int y;

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	public Pair() {

	}

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

}


Measured memory_bytes: 35092
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>

int main(void)
{
	int n;
	char buffer[1000];
	int i;
	short kind = 3;

	fgets(buffer, sizeof(buffer), stdin);
	fgets(buffer, sizeof(buffer), stdin);

	n = strlen(buffer);
	for (i = 0; i < n; ++i){
		if (buffer[i] == 'Y'){
			kind = 4;
		}
	}
	if (kind == 3){
		printf("Three\n");
	}
	else if (kind == 4){
		printf("Four\n");
	}
	return 0;
}


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

using namespace std;
typedef long long LL;
// typedef pair<double, double> P;
// typedef pair<P, LL> PP;

// vector<P> px(110000);
// vector<P> py(110000);
int main() {
  // #ifndef ONLINE_JUDGE
 // freopen("input", "r", stdin);
  //std::vector<int> v;
  //freopen("output", "w", stdout);
  int n;
  cin>>n;
  cout<<"ABC"<<n<<endl;
  //cout<<"????"<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int X, Y;
    cin >> X >> Y;
    int ans = 0;
    if(X == 1) ans = 300000;
    else if(X == 2) ans = 200000;
    else if(X == 3) ans = 100000;

    if(Y == 1) ans += 300000;
    else if(Y == 2) ans += 200000;
    else if(Y == 3) ans += 100000;

    if(X == 1 and Y == 1) ans += 400000;

    cout << ans << endl;

    return 0;
}

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

int main()
{
  long long a, b, c, k;
  cin >> a >> b >> c >> k;
  
  if(a >= k)
  {
    cout << k << endl;
  }
  else if(a + b >= k)
  {
    cout << a << endl;
  }
  else
  {
    cout << a - k + b + a << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int main()
{

    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a!=c)
        cout<<"Yes";
    else if(a==c&&a!=b)
        cout<<"Yes";
    else if(b==c&&b!=a)
        cout<<"Yes";
    else
        cout<<"No";
    return 0;
}


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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  map<int, int> data;
  int j = 1;
  for(int i = 1; i <= 100; i++){
    if(a % i == 0 && b % i == 0){
      data[i] = j;
    }
  }
  vector<int> answer(data.size());
  int i = 0;
  for(auto x : data){
    auto a = x.first;
    auto b = x.second;
    answer.at(i) = a;
    i++;
  }
  cout << answer.at(answer.size() - k) << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
#include <climits>
#include <queue>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i = 0; i < (ll)(n); ++i)
template<class T> inline bool chmax(T& a, T b) { if(a < b){ a=b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if(a > b){ a=b; return 1; } return 0;}

int main(){
	int N, Q;
	cin >> N >> Q;
	string s;
	cin >> s;
	vector<pair<int,int>> LR(Q);
	REP(i,Q){
		cin >> LR[i].first >> LR[i].second;
		// 0-based
		LR[i].first--;
		LR[i].second--;
	}
	
	vector<int> count(N,0);
	REP(i, N-1){
		if(i!=0) count[i] = count[i-1];
		if(s[i]=='A' && s[i+1]=='C'){
			count[i]++;
		}
	}
	count[N-1] = count[N-2];
	
	REP(i,Q){
		cout << count[LR[i].second-1]-count[LR[i].first-1] << endl;
	}
	
	
	return 0;
}

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

using namespace std;

int main()
{
    string s;
    cin>>s;
    int n=s.length()-1;
    if(s[n]=='s'){
        s+="es";
    }
    else{
        s+="s";
    }
   cout<<s;
   return 0;
}

Measured memory_bytes: 3624
#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;
#define light ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define endl "\n"
#define pb push_back
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define REP(i,a,b) for(ll i = a; i < b; i++)
#define REPE(i,a,b) for(ll i = a; i <= b; i++)
#define REPR(i,a,b) for(ll i = a; i >= b; i--)
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / gcd(a, b)
#define bins(v, x) binary_search(v.begin(), v.end(), x)
const double pi = 2*acos(0.0);
const int INF = 1e9+1;
const int MOD = 1e9+7;
const int MOD1 = 998244353;

using ll = long long;
using ld = long double;
using vi = vector<int>;

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modExp(ll base, ll exp, ll mod) {
   ll res = 1;
   while (exp > 0) {
    	if (exp % 2 == 1) {
        	res= (res * base) % mod;
		}
      exp = exp >> 1;
      base = (base * base) % mod;
   }
   return res;
}

ll inverse(ll base, ll exp, ll mod) {
   return modExp(base, exp - 2, mod);
}

bool compare(const pair<int,int> &i, const pair<int,int> &j) {
   return (i.S > j.S || (i.S == j.S && i.F > j.F));
}

void test() {
   ll n;
   cin >> n;
   vector<ll> a(n);
   REP(i,0,n) cin >> a[i];
   sort(all(a));
   
   ll cnt = 0;
   for(int i = 0; i < n-2; i++) {
      for(int j = i+1; j < n-1; j++) {
         for(int k = j+1; k < n; k++) {
            if(a[i] + a[j] > a[k] && a[j] + a[k] > a[i] && a[k] + a[i] > a[j] && a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) {
               //cout << i << " " << j << " " << k << "\n";
               cnt++;
            }
         }
      }
   }
   cout << cnt;
}

int main() {
   //freopen("input.txt","r",stdin);
   //freopen("output.txt","w",stdout);
   light;
   cout.precision(15);
   cout << fixed;

   int t = 1;
   //cin >> t;
   for(int i = 1; i <= t; i++) {
      //cout << "Case #" << i << ": ";
      test();
   }
   return 0;
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main() {
  int n, q, k;
  cin >> n;
  vector<int> a(n - 1), b(n - 1);
  vector<ll> c(n - 1), l(n);
  vector<vector<pair<int, ll>>> r(n);
  for(int i = 0; i < n - 1; i++) {
    cin >> a.at(i) >> b.at(i) >> c.at(i);
    r.at(--a.at(i)).push_back({--b.at(i), c.at(i)});
    r.at(b.at(i)).push_back({a.at(i), c.at(i)});
  }
  cin >> q >> k;
  queue<pair<int, int>> que;
  pair<int, int> p;
  for(int i = 0; i < r.at(k - 1).size(); i++) {
    l.at(r.at(k - 1).at(i).first) = r.at(k - 1).at(i).second;
    que.push({r.at(k - 1).at(i).first, k - 1});
  }
  while(que.size()) {
    p = que.front();
    que.pop();
    for(int i = 0; i < r.at(p.first).size(); i++) {
      if(r.at(p.first).at(i).first == p.second)
        continue;
      l.at(r.at(p.first).at(i).first) =
          l.at(p.first) + r.at(p.first).at(i).second;
      que.push({r.at(p.first).at(i).first, p.first});
    }
  }
  vector<int> x(q), y(q);
  for(int i = 0; i < q; i++)
    cin >> x.at(i) >> y.at(i);
  for(int i = 0; i < q; i++)
    cout << l.at(x.at(i) - 1) + l.at(y.at(i) - 1) << endl;
}

Measured memory_bytes: 13568
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws NumberFormatException, IOException {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());    //??´??°n

        int[] x = new int[n];   //????????????x??¨?????????
        int[] y = new int[n];   //????????????y??¨?????????

//      x???????´????????????????????????????????´?
        String[] inputX = br.readLine().split(" ");
        for(int i = 0; i < inputX.length; i++){
            x[i] = Integer.parseInt(inputX[i]);
        }
//      y???????´????????????????????????????????´?
        String[] inputY = br.readLine().split(" ");
        for(int i = 0; i < inputX.length; i++){
            y[i] = Integer.parseInt(inputY[i]);
        }
        double p1 = 0;
        double p2 = 0;
        double p3 = 0;
        double infinity = 0;

        for(int i = 0; i < n; i++){
            p1 += Math.abs(x[i] - y[i]);
            p2 += Math.abs(Math.pow(x[i] - y[i], 2));
            p3 += Math.abs(Math.pow(x[i] - y[i], 3));
            if(infinity < Math.abs(x[i] - y[i])){
                infinity = Math.abs(x[i] - y[i]);
            }
        }
        System.out.println(p1);
        System.out.println(Math.sqrt(p2));
        System.out.println(Math.cbrt(p3));
        System.out.println(infinity);
    }
}

Measured memory_bytes: 24528
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<functional>
#include<vector>
#include<set>
#include<queue>
using namespace std;
#define f(i,n) for(int i=0;i<(int)n;i++)
#define MOD 1000000009

int main(void){
	char a[100];
	char b[100];
	f(i, 100){
		a[i] = 0;
		b[i] = 0;
	}
	int k, s;
	int n, m;
	int x, y, z;
	int ans = 0;

	scanf("%s", a);
	scanf("%s", b);
	for (int i = strlen(a) - strlen(b); i >= 0;i--){
		x = 0;
		f(j, strlen(b)){
			if (a[i + j] == '?' || a[i + j] == b[j])x++;
		}
		if (x == strlen(b)){
			f(j, strlen(b)){
				a[i + j] = b[j];
			}
			f(j, strlen(a)){
				if (a[j] == '?')a[j] = 'a';
			}
			ans = 1;
			break;
		}
	}

	if(ans==1)f(i,strlen(a))printf("%c",a[i]);
	else printf("UNRESTORABLE");
	printf("\n");

	return 0;
}

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

int main() {
    std::ios::sync_with_stdio(false);
    lld tc = 1;
    // cin >> tc;
    while (tc--) {
        lld A, B, C;
        cin >> A >> B >> C;
        lld k;
        cin >> k;
        if (C > B && B > A) {
            cout << "Yes\n";
        } else {
            lld f = 0;
            for (lld i = 0; i <= k; i++) {
                lld toB = k - i;
                lld newB = B * pow(2, toB);
                lld newC = C * pow(2, i);
                // cout << A << " " << newB << " " << newC << "\n";
                if ( newC > newB && newB > A) {
                    cout << "Yes\n";
                    f = 1;
                    break;
                }
            }
            if (f == 0) {
                cout << "No\n";
            }
        }
    }
}

Measured memory_bytes: 4116
#include <bits/stdc++.h>
using namespace std;
int n,k,r,s,p;
string t;
int getPoint(char c){
    switch(c){
        case 'r':
            return p;
            break;
        case 's':
            return r;
            break;
        case 'p':
            return s;
            break;
    }
}
int main(){
    cin >> n >> k; 
    cin >> r >> s >> p; 
    cin >> t;
    vector <int> eachPoint(n);
    for(int i = 0; i < n; i++){
        eachPoint[i] = getPoint(t[i]);
    }
    //どの勝負を捨てるか選ぶ。
    //n/k個の組について考える。
    vector <int> dp(n,-1);
        //毎回t[i]が変わるなら全部勝てる。
        //t[i]が連続する区間はどれを捨てるか考える。
        //基本的には捨てる勝負が少ない方が望ましい。
        //奇数個連続する場合は、偶数個目を捨てる。
        //偶数個目についてはどちらでもよい。
        {
            int index = 0;
            char lastValue = t[index];
            while(index<n){
                int index2 = index+k;
                if(dp[index]==-1){
                    while(index2<n){
                        if(t[index]==t[index2]){
                            if(dp[index]==-1){
                                dp[index]=0;
                            }
                            dp[index2]=0;
                            dp[index]++;
                        }else{
                            break;
                        }
                        index2+=k;
                    }
                }
                index++;
            }
        }
        #if 0

        for(int i = 0; i < n; i++){
            cout << t[i] << " ";
        }
        cout << endl;
        for(int i = 0; i < n; i++){
            cout << dp[i] << " ";
        }
        cout << endl;
        #endif
        {
            int index = 0;
            while(index < n){
                if(dp[index]==0){
                    index++;
                }else if(dp[index]==-1){
                    index++;
                }else{
                    int index2 = index;
                    int cnt = 1;
                    while(index2<=index+k*dp[index]){
                        if(index2<n){
                            if(cnt%2==0){
                                eachPoint[index2]=0;
                            }
                            cnt++;
                            index2+=k;
                        }else{
                            break;
                        }
                    }
                    index++;
                }
            }
            long ans = 0;
            for(int i = 0; i < n; i++){
                ans+=eachPoint[i];
            }
            cout << ans << endl;
        }
        #if 0
        for(int i = 0; i < n; i++){
            cout << t[i];
            if(i%k==k-1){
                cout << endl;
            }
        }
        cout << endl;
        for(int i = 0; i < n; i++){
            cout << dp[i];
            if(i%k==k-1){
                cout << endl;
            }
        }
        cout << endl;
        #endif

    return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#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;
ll gcd(ll x, ll y)
{
  if (y > x)
  {
    ll tmp = y;
    y = x;
    x = tmp;
  }
  if (y == 0)
    return x;
  gcd(y, x % y);
}

int main(int argc, char const *argv[])
{
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll cd = c * d / gcd(c, d);
  ll cdwari = 0;
  if (a % cd == 0)
  {
    cdwari++;
  }
  ll tmp = a / cd + 1;
  ll tmp2 = b / cd;
  if (tmp <= tmp2)
  {

    cdwari += tmp2 - tmp + 1;
  }
  ll cwari = 0;
  if (a % c == 0)
  {
    cwari++;
  }
  tmp = a / c + 1;
  tmp2 = b / c;
  if (tmp <= tmp2)
  {
    cwari += tmp2 - tmp + 1;
  }
  ll dwari = 0;
  if (a % d == 0)
  {
    dwari++;
  }
  tmp = a / d + 1;
  tmp2 = b / d;
  if (tmp <= tmp2)
  {
    dwari += tmp2 - tmp + 1;
  }
  cout << b - a + 1 - (dwari + cwari - cdwari) << endl;
  return 0;
}


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

int main(){
  int m[100];
  int n,k,a,b;

  cin >> n >> k;

  for(int i=0;i<n;i++)m[i] = -1;
  for(int i=0;i<k;i++){
    cin >> a >> b;
    m[a-1] = b-1;
  }

  int dp[101][3][3];
  for(int i=0;i<n;i++)
    for(int j=0;j<3;j++)
      for(int k=0;k<3;k++)dp[i][j][k] = 0;
  
  for(int i=0;i<n;i++){
    if(i==0){
      if(m[i]<0){
	for(int j=0;j<3;j++)dp[i][j][(j+1)%3] = 1;
      }else{
	dp[i][m[i]][(m[i]+1)%3] = 1;
      }
    }else{
      for(int j=0;j<3;j++){
	for(int k=0;k<3;k++){
	  if(m[i]<0){
	    for(int l=0;l<3;l++){
	      if(l==k && k==j)continue;
	      else {
	      dp[i][l][j] += dp[i-1][j][k]; 
	      dp[i][l][j] %= 10000;
	      }
	    }
	  }else{
	    if(!(j==m[i] && k==m[i]) ){
	      dp[i][m[i]][j] += dp[i-1][j][k];
	      dp[i][m[i]][j] %= 10000;
	    }
	  }
	}
      }
    }
  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++)for(int k=0;k<3;k++)cout << dp[i][j][k] << " ";
    cout << endl;
  }
  */
  int ans = 0;
  for(int i=0;i<3;i++)
    for(int j=0;j<3;j++){
      ans += dp[n-1][i][j];
      ans %= 10000;
    }

  cout << ans << endl;
}

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

int main() {
  using i64 = long long;
  constexpr i64 MInf = std::numeric_limits<i64>::lowest() / 2;

  int n;
  std::cin >> n;
  std::vector<i64> a(n);
  for (auto &e : a) {
    std::cin >> e;
  }

  std::map<std::pair<int, int>, i64> memo;
  std::function<i64(int, int)> solve, calc;

  solve = [&](int i, int k) -> i64 {
    auto itr = memo.find({i, k});
    if (itr == memo.end()) {
      itr = memo.insert({{i, k}, calc(i, k)}).first;
    }
    return itr->second;
  };

  calc = [&](int i, int k) -> i64 {
    if (k < 0 || (i + 1) / 2 < k)
      return MInf;
    if (i <= 0)
      return 0;
    return std::max(solve(i - 1, k), solve(i - 2, k - 1) + a[i - 1]);
  };

  std::cout << solve(n, n / 2) << "\n";
}


Measured memory_bytes: 46988
#include<bits/stdc++.h>
using namespace std;
#define ALL(a) begin(a), end(a)
int main()
{
    int n, a, b, ans = 0;
    cin >> n >> a >> b;
    for (int i = 1; i <= n; ++i) {
        int x = i, y = 0;
        while (x)
            y += x % 10, x /= 10;
        if (a <= y && y <= b)
            ans += i;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<string>
#include<string.h>
#include<map>
using namespace std;
char cs[20]="*+-&^|0123456789";
char in[20];
map<pair<string,int>,int>dp;
int n;
int m;
int cur;
string str;
int e1();
int e2();
int e3();
int e4();
int e5();
int fact(){
	if(str[cur]=='('){
		cur++;
		int ret=e5();
		cur++;
		return ret;
	}
	int ret=0;
	while('0'<=str[cur]&&str[cur]<='9'){
		ret*=10;
		ret+=str[cur]-'0';
		cur++;
	}
	return ret;
}
int e1(){
	int ret=fact();
	while(str[cur]=='*'){
		cur++;
		ret*=fact();
	}
	return ret;
}
int e2(){
	int ret=e1();
	while(str[cur]=='+'||str[cur]=='-'){
		char t=str[cur];
		cur++;
		if(t=='+')ret+=e1();
		else ret-=e1();
	}
	return ret;
}
int e3(){
	int ret=e2();
	while(str[cur]=='&'){
		cur++;
		ret&=e2();
	}
	return ret;
}
int e4(){
	int ret=e3();
	while(str[cur]=='^'){
		cur++;
		ret^=e3();
	}
	return ret;
}
int e5(){
	int ret=e4();
	while(str[cur]=='|'){
		cur++;
		ret|=e4();
	}
	return ret;
}
bool valid(){
	int kk=0;
	if(str[0]=='0')return false;
	if((str[0]<'0'||str[0]>'9')&&str[0]!='('&&str[0]!=')')return false;
	if((str[m-1]<'0'||str[m-1]>'9')&&str[m-1]!='('&&str[m-1]!=')')return false;
	
	for(int i=0;i<m;i++){
		if(str[i]=='(')kk++;
		if(str[i]==')')kk--;
		if(kk<0)return false;
	}
	if(kk)return false;
	for(int i=0;i<m-1;i++){
		if(str[i]=='('&&(str[i+1]<'0'||str[i+1]>'9')&&str[i+1]!='(')return false;
		if(str[i]==')'&&!(str[i+1]<'0'||str[i+1]>'9'))return false;
		if(str[i+1]==')'&&(str[i]<'0'||str[i]>'9')&&str[i]!=')')return false;
		if(str[i+1]=='('&&!(str[i]<'0'||str[i]>'9'))return false;
		if((str[i]<'0'||str[i]>'9')&&str[i+1]=='0')return false;
		if((str[i]<'0'||str[i]>'9')&&str[i]!='('&&str[i]!=')'&&
			(str[i+1]<'0'||str[i+1]>'9')&&str[i+1]!='('&&str[i+1]!=')')return false;
	}
	return true;
}
int solve(int a,string b){
	if(dp.count(make_pair(b,a)))return dp[make_pair(b,a)];
	if(a==n){
		cur=0;
		str=b;
		int ret=e5();
	//	if(ret<20)printf("%d %s: %d\n",a,b.c_str(),ret);
		return dp[make_pair(b,a)]=ret;
	}
	int len=b.size();
	int ret=-999999999;
	if(a%2)ret=999999999;
	for(int i=0;i<len;i++){
		string c="";
		for(int j=0;j<i;j++)c=c+b[j];
		for(int j=i+1;j<len;j++)c=c+b[j];
		cur=0;
		str=c;
		m=c.size();
		if(valid()){
			if(a%2)ret=min(ret,solve(a+1,c));
			else ret=max(ret,solve(a+1,c));
		}
	}
	for(int i=0;i<=len;i++){
		string c="";
		for(int j=0;j<i;j++)c=c+b[j];
		c+='*';
		for(int j=i;j<len;j++)c=c+b[j];
		for(int j=0;j<16;j++){
			c[i]=cs[j];
			str=c;
			m=c.size();
			if(valid()){
				if(a%2)ret=min(ret,solve(a+1,c));
				else ret=max(ret,solve(a+1,c));
			}
		}
	}
	//printf("%d %s: %d\n",a,b.c_str(),ret);
	return dp[make_pair(b,a)]=ret;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		scanf("%s",in);
	
		dp.clear();
		
		while(a>2)a-=2;
		n=a;
		string tmp=in;
		printf("%d\n",solve(0,tmp));
	}
}

Measured memory_bytes: 1880
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
    public static int CURRENT_YEAR = 1000;
    public static int CURRENT_MONTH = 1;
    public static int CURRENT_DAY = 1;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int peopleCount = Integer.valueOf(sc.nextLine());

        for (int i = 0; i < peopleCount; i ++) {
            System.out.println(calculateDays(sc.nextLine()));
        }

    }

    public static int calculateDays(String YMD) {
        int birthYear = Integer.valueOf(YMD.split(" ")[0]);
        int birthMonth = Integer.valueOf(YMD.split(" ")[1]);
        int birthDay = Integer.valueOf(YMD.split(" ")[2]);

         int daysFromBirthYear = 1;

        // by years
        for (int y = birthYear; y < CURRENT_YEAR; y++) {
            if(y % 3 == 0) {
                daysFromBirthYear += 200;
            } else {
                daysFromBirthYear += 195;
            }
        }

        int dayOfBorn = 0;
        if(birthYear % 3 == 0) {
            dayOfBorn = (birthMonth - 1) * 20 + birthDay;
        } else {
            for (int m = 1; m < birthMonth; m ++) {
                dayOfBorn += m % 2 == 0 ? 19 : 20;
            }
            dayOfBorn += birthDay;
        }


        return daysFromBirthYear - dayOfBorn;
    }
}


Measured memory_bytes: 26384
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

const int MAX_N = 100 + 2;
const int MAX_K = 100000 + 2;
int N;
int a[MAX_N];
int dp[MAX_K];

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

  int N, K;
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> a[i];

  memset(dp, 0, sizeof(dp));

  dp[0] = -1;

  for (int k = 1; k <= K; k++) {

    int ans = 1;

    for (int i = 0; i < N; i++) {
      if (k - a[i] >= 0) {
	if (dp[k - a[i]] == -1) {
	  ans = -1;
	  break;
	}
      }
    }

    if (ans == -1) dp[k] = 1;
    else dp[k] = -1;

  }

  if (dp[K] == 1) cout << "First" << endl;
  else cout << "Second" << endl;
  
  
  return 0;
}



Measured memory_bytes: 3516
#include <stdio.h>
#include <iostream>
using namespace std;

//????????????
class Circle {
private:
	int x, y, r;
public:
	Circle(int x, int y, int r);
	void getRLTB(int rltb[]);
};

//?????????????????????
Circle::Circle(int x, int y, int r)
{
	this->x = x;
	this->y = y;
	this->r = r;
}

void Circle::getRLTB(int rltb[])
{
	rltb[0] = x + r;
	rltb[1] = x - r;
	rltb[2] = y + r;
	rltb[3] = y - r;
}


//????????¢?????????
class Rectangle {
private:
	int right, left = 0, top, bottom = 0;
public:
	Rectangle(int w, int h);
	bool judge(Circle cir);
};

//?????????????????????
Rectangle::Rectangle(int w, int h)
{
	this->right = w;
	this->top = h;
}

bool Rectangle::judge(Circle cir)
{
	int rltb[4];
	cir.getRLTB(rltb);
	
	if (rltb[0] > right) return false;
	if (rltb[1] < left) return false;
	if (rltb[2] > top) return false;
	if (rltb[3] < bottom) return false;
	
	return true;
}


int main(void)
{		
	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;
	
	Circle cir(x, y, r);
	Rectangle rec(w, h);
	
	if (rec.judge(cir)) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
}

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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

int main()
{
    int a , b;
    cin >> a >> b;
    for(int i = 1;i <= 1000000;i++){
        int d1 = (i * 8)/100;
        int d2 = (i * 10)/100;
        if(d1 == a and d2 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <utility>
#include <vector>
#include <map>
#include <stack>
#include <iomanip>
#include <set>
#include <sstream>
#include <cmath>
#include <deque>
#include <list>
#include <bitset>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long int64;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define FST first
#define SND second

signed main(){
    int A,B,T;
    cin>>A>>B>>T;
    int res = 0;
    res = T/ A * B;
    cout << res << endl;
     return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;
   
int main() {
    double a , b;
    cin >> a >> b;
    cout << round( ( a + b ) / 2 );
}


Measured memory_bytes: 3804
def main():
    n, k = map(int, input().split())
    a = list(map(int, input().split()))
    op = 0
    while True:
        new = [0 for _ in range(n + 1)]
        for i in range(n):
            new[max(0, i - a[i])] += 1
            new[min(n, i + a[i] + 1)] -= 1
        for i in range(1, n + 1):
            new[i] += new[i - 1]
        a = new[:-1]
        op += 1
        if op == k or all(aa == n for aa in a):
            break
    print(" ".join(map(str, a)))


if __name__ == '__main__':
    main()


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

#define dforsn(i,s,n) for(int i=int(n-1);i>=int(s);i--)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define dforn(i,n) for(int i=int(n-1);i>=0;i--)
#define forn(i,n) for(int i=0;i<int(n);i++)
#define D(a) cerr << #a << " = " << a << endl
#define all(a) a.begin(),a.end()
#define si(a) int((a).size())
typedef pair<int,int> pii;
typedef long long int ll;
typedef vector<int> vi;
#define pb emplace_back
#define mp make_pair
#define snd second
#define fst first

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    
    ll n,k; cin >> n >> k;
    n %= k;
    if (k-n < n) n = k-n;
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
int main(){
  int n,h,max=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&h);
    if(max-1>h){
      printf("No");
      return 0;
    }
    else{
      max=std::max(max,h);
    }
  }
  printf("Yes");
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0; (i)<(n); (i)++)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define ll long long
#define pii pair<int,int> 
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
const int INF = 1001001001;
//int 2×10の9乗
//vector<vector<int>> a(n, vector<int>(m));
  //rep(i,n) rep(j,m) cin >> a[i][j]; 
//cout << fixed << setprecision(10);
//int gcd(int x, int y){
  //if(y==0) return x;
  //return gcd(y, x%y);
//}
//sort小さい順(昇順)
//g++ code.cpp   ./a.out 
int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  int ans=0;
  rep(i,n){
    for(int j=i; j<n; j++) ans+=d[i]*d[j];
  }
  rep(i,n) ans-=d[i]*d[i];
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include <stack>
#include <queue> // priority_queue も入ってる
#include <set>   // 要素数は size() で取得
#include <map>
#include <array> // sizeはコンパイル時定数で固定
#include <vector>
#include <numeric>   // accumulate, gcd
#include <algorithm> // count_ifに必要
#include <iomanip>   // cout << setprecision(15) << x で小数の出力精度を指定
#include <tuple>
#include <utility> //pair

using namespace std;
// 問題が起こるまでintは使用禁止2020-04-13
using ll = long long;

template <class InputIterator, class T>
bool contains(InputIterator iterator, const T &value)
{
    if (find(iterator.begin(), iterator.end(), value) == iterator.end())
        return false;
    else
        return true;
}

template <class InputIterator>
auto sum(InputIterator iterator)
{
    return accumulate(iterator.begin(), iterator.end(), 0);
}

// =========ここまでテンプレ============

int main()
{
    ll n;
    set<string> s;
    cin >> n;
    for (ll i = 0; i < n; i++)
    {
        string k;
        cin >> k;
        s.insert(k);
    }
    cout << s.size();
}

Measured memory_bytes: 15728
#include <vector>
#include <set>
#include <cstdio>
using namespace std;

int main(){
    int N;
    long long W,tV=0,tW=0,x=0;
    scanf("%d%lld",&N,&W);
    vector<pair<long long,long long> >v(N);
    for(int i=0;i<N;i++)scanf("%lld%lld",&v[i].second,&v[i].first),tV+=v[i].first,tW+=v[i].second;
    if(W>tW)W=tW;
    if(tW<10000000){
        vector<long long>bag(W+1);
        bag[0]=1;
        for(auto &e:v){
            x+=e.second;
            if(x>W)x=W;
            for(int j=x;j>=e.second;j--)if(bag[j-e.second]&&bag[j]<bag[j-e.second]+e.first)
                bag[j]=bag[j-e.second]+e.first;
        }
        for(int i=0;i<W;i++)bag[i+1]=max(bag[i+1],bag[i]);
        printf("%lld\n",bag[W]-1);
    }else if(tV<10000000){
        vector<long long>bag(tV+1);
        bag[0]=1;
        for(auto &e:v){
            x+=e.first;
            for(int j=x;j>=e.first;j--)if(bag[j-e.first]&&(!bag[j]||bag[j]>bag[j-e.first]+e.second))
                bag[j]=bag[j-e.first]+e.second;
        }
        int i=0,mi;
        for(;i<=tV;i++)if(bag[i]&&bag[i]-1<=W)mi=i;
        printf("%d\n",mi);
    }else if(N<=40){
        int n=N/2;
        set<pair<long long,long long> >se1,se2;
        for(int i=0;i<1<<n;i++){
            long long V=0,w=0;
            for(int j=0;j<n;j++)if(i&(1<<j))V+=v[j].first,w+=v[j].second;
            se1.emplace(w,V);
        }
        for(int i=0;i<1<<(N-n);i++){
            long long V=0,w=0;
            for(int j=0;j<(N-n);j++)if(i&(1<<j))V+=v[j+n].first,w+=v[j+n].second;
            se2.emplace(w,V);
        }
        for(auto it=se1.begin();it!=se1.end();){
            auto it2=it;
            for(++it2;it2!=se1.end()&&it->second>=it2->second;)it2=se1.erase(it2);
            ++it;
        }
        for(auto it=se2.begin();it!=se2.end();){
            auto it2=it;
            for(++it2;it2!=se2.end()&&it->second>=it2->second;)it2=se2.erase(it2);
            ++it;
        }
        long long r=0;
        for(auto &e1:se1){
            auto it=se2.lower_bound({W-e1.first+1,0});
            if(it!=se2.begin()){
                --it;
                r=max(r,e1.second+it->second);
            }
        }
        printf("%lld\n",r);
    }else{
        return 1;
    }
}


Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
String A = sc.next();
String B = sc.next();
int mir = 0;
if(A.length() > B.length()){System.out.println("GREATER");
}else if(A.length() < B.length()){System.out.print("LESS");
}else if(A.length() == B.length()){
while(true){
try{
int a = Integer.parseInt(String.valueOf(A.charAt(mir)));
int b = Integer.parseInt(String.valueOf(B.charAt(mir)));
if(a > b ){System.out.println("GREATER");break;}
else if(a < b){System.out.println("LESS");break;}
mir++;}
catch(IndexOutOfBoundsException e){System.out.println("EQUAL");break;}
}
}
}
}

Measured memory_bytes: 21844
# include <cstdio>
# include <iostream>
# include <algorithm>
# include <queue>
# include <map>
# include <vector>
# include <cmath>
# include <cstring>
# define R register int
# define ll long long

using namespace std;

const int N=200005;
const double eps=1e-10;
int n,zr[N],a2[N],a5[N],z0,cnt;
double a[N];
int t[70][70][20];
struct aa
{
	int a,b,c,t;
}zt[N];

bool zs (double x)
{
	if(abs(x-(ll)x)<eps) return 1;
	return 0;
}

int po[100];

int main()
{
	scanf("%d",&n);
	po[0]=1; for (R i=1;i<=9;++i) po[i]=po[i-1]*10;
	for (R i=1;i<=n;++i)
	{
		scanf("%lf",&a[i]);
		ll ta=a[i]*1000000000+0.5;
		while(ta%10==0) ta/=10,zr[i]++;
		zr[i]=max(9-zr[i],0);
		ta=a[i]*po[ zr[i] ]+0.5;
		while(ta%2==0) a2[i]++,ta/=2;
		while(ta%5==0) a5[i]++,ta/=5;
		while(a2[i]&&a5[i]&&zr[i])
			a2[i]--,a5[i]--,zr[i]--;
		t[ a2[i] ][ a5[i] ][ zr[i] ]++;
		if(zr[i]==0) z0++;
	}
	for (R a2=0;a2<=65;++a2)
		for (R a5=0;a5<=65;++a5)
			for (R z1=0;z1<=10;++z1)
				if(t[ a2 ][ a5 ][ z1 ])
					++cnt,zt[cnt].a=a2,zt[cnt].b=a5,zt[cnt].c=z1,zt[cnt].t=t[a2][a5][z1];
	ll ans=0;
	for (R i=1;i<=cnt;++i)
	{
		if(zt[i].c==0) ans+=1LL*zt[i].t*(zt[i].t-1)/2;
		for (R j=i+1;j<=cnt;++j)
		{
			if(min(zt[i].a+zt[j].a,zt[i].b+zt[j].b)>=zt[i].c+zt[j].c)
				ans+=1LL*zt[i].t*zt[j].t;
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 7716
use proconio::input;

fn gcd(x: isize, y: isize) -> isize {
    if y == 0 {
        x.abs()
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    input! {
        k: isize,
    }

    let mut ans = 0;

    for a in 1..=k {
        for b in 1..=k {
            for c in 1..=k {
                ans += gcd(gcd(a, b), c);
            }
        }
    };

    println!("{}", ans);
}


Measured memory_bytes: 2128
using System;
using System.Linq;

class Program
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        for (int i = 0; i < n; i++)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).OrderBy(x => x).ToArray();
            int a = input[0];
            int b = input[1];
            int c = input[2];
            Console.WriteLine((a * a + b * b == c * c) ? "YES" : "NO"); 
        }
    }
}

Measured memory_bytes: 9916
N = int(input())
import itertools
num = [i for i in range(1,101)]
comb = list(itertools.combinations_with_replacement(num, 3))
cnt_list = [0] * 10001
for c in comb:
    x = c[0]
    y = c[1]
    z = c[2]
    n = x**2 + y**2 + z**2 + x*y + y*z + z*x
    if n <= 10000:
        if x == y and y == z and z == x:
            cnt_list[n] += 1
        elif x == y or y == z or z == x:
            cnt_list[n] += 3
        else:
            cnt_list[n] += 6
for i in range(1,N+1):
    print(cnt_list[i])

Measured memory_bytes: 21456
#include<stdio.h>

int main(void)
{
  int a,b,c,k;
  scanf("%d%d%d%d",&a,&b,&c,&k);

  int max=0;
  if(a>=b&&a>=c){
    max =a;
  }else if(b>=a&&b>=c){
    max = b;
  }else{
    max = c;
  }

  int max_2=max;
  for(int i=0; i<k; i++){
    max_2 *=2;
  }

    printf("%d",a+b+c-max+max_2);
    return 0;

}


Measured memory_bytes: 128