akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 3010;

int n, m, ans, cnt;
char s[N][N];
bool ab[N][2];
int dp[N][3];

void prog() {
    for (int i = 1; i <= cnt + 1; ++i) {
        dp[i][2] = *max_element(dp[i - 1], dp[i - 1] + 3);
        dp[i][0] = ab[i][0] ? (max(dp[i - 1][0], dp[i - 1][2]) + 1) : 0;
        dp[i][1] = ab[i][1] ? (max(dp[i - 1][1], dp[i - 1][2]) + 1) : 0;
    }
    ans += dp[cnt + 1][2];
}

int main() {

    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%s", s[i] + 1);
    for (int k = 2; k <= n + m; ++k) {
        for (int i = 1; i <= n; ++i) {
            int j = k - i;
            if (j < 1 || j > m)
                continue;
            if (s[i][j] != 'G') {
                if (cnt)
                    prog();
                cnt = 0;
            } else {
                ++cnt;
                ab[cnt][0] = s[i - 1][j] == 'R' && s[i + 1][j] == 'W';
                ab[cnt][1] = s[i][j - 1] == 'R' && s[i][j + 1] == 'W';
            }
        }
        if (cnt)
            prog();
        cnt = 0;
    }
    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 12068
n = int(input())
a = [int(i) for i in input().split()]
M = max(a)
m = min(a)
print(2*n-1)
if abs(M) > abs(m):
    Mi = a.index(M)
    for i in range(n):
        # a[i] += a[Mi]
        print(Mi+1,i+1)
    for i in range(n-1):
        # a[i+1] += a[i]
        print(i+1,i+2)
else:
    mi = a.index(m)
    for i in range(n):
        # a[i] += a[mi]
        print(mi+1,i+1)
    for i in range(n-1)[::-1]:
        # a[i] += a[i+1]
        print(i+2,i+1)
# print(a)

Measured memory_bytes: 9160
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//																				NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define mod 100000007
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	int n,m,x,y;
	cin>>n>>m;
	vector<int> v(n);
	fill(v.begin(),v.end(),-1);
	for(int i=0;i<m;i++){
		cin>>x>>y;
		--x;
		if(v[x] == -1 || v[x]==y){
			v[x] = y;
		} else {
			cout<<"-1";
			return 0;
		}
	}
	if(n>1 && v[0]==0){
		cout<<"-1";
		return 0;
	} else {
		for(int i=0;i<n;i++){
			if(v[i]==-1){
				if(!i){
                    if(n==1){
                        v[i] = 0;
                    } else {
                        v[i] = 1;
                    }
				} else {
					v[i] = 0;
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		cout<<v[i];
	}
	return 0;
}

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

int main()
{

	int SumScore, Score;

	SumScore = 0;

	for( int i = 0; i < 5; i++ ) {
		
		cin >> Score;

		if( Score >= 40 ) SumScore += Score;
		else			  SumScore += 40;

	}

	cout << SumScore / 5 << endl;

	return 0;

}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
//const ll  MOD = 1000000007;
const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int N;
int A[15];
int ans = 0;

void dfs(vector<int> v){
    if(v.size() == N){
        ll sum = 1;
        REP(i,N){
            if(v[i] == 0) sum *= (A[i] - 1);
            else if(v[i] == 1) sum *= A[i];
            else sum *= (A[i] + 1);
        }
        if(sum % 2 == 0) ans++;
    }
    else{
        REP(i,3){
            auto tmp = v;
            tmp.push_back(i);
            dfs(tmp);
        }
    }
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    REP(i,N) cin >> A[i];
    vector<int> v;
    dfs(v);
    cout << ans << endl;
}

Measured memory_bytes: 256
//------------------------------>> tsukasa_diary's template <<------------------------------//
#include <bits/stdc++.h>
using namespace std;

#define for_(i,a,b) for(int i=(a);i<(b);++i)
#define for_rev(i,a,b) for(int i=(a);i>=(b);--i)
#define allof(a) (a).begin(),(a).end()
#define minit(a,b) memset(a,b,sizeof(a))

using lint = long long;
using pii = pair< int, int >;

template< typename T > using Vec = vector< T >;

template< typename T > bool in_range(T x, T lb, T ub) { return lb <= x && x < ub; }
template< typename T > bool in_range(T x, T y, T lb, T ub) { return in_range(x, lb, ub) && in_range(y, lb, ub); }

template< typename T > void modAdd(T& a, T b, T mod) { a = (a + b) % mod; }
template< typename T > void modMul(T& a, T b, T mod) { a = (a * b) % mod; }
template< typename T > void minUpdate(T& a, T b) { a = min(a, b); }
template< typename T > void maxUpdate(T& a, T b) { a = max(a, b); }

int bitCount(int x) { return __builtin_popcount(x); }
int bitCount(lint x) { return __builtin_popcountll(x); }

const int dx[4] = {0,1,0,-1}, dy[4] = {-1,0,1,0};
const int Dx[8] = {0,1,1,1,0,-1,-1,-1}, Dy[8] = {-1,-1,0,1,1,1,0,-1};



//--------------8---------------->> coding space <<-----------------8-------------//



int main() {
	string S;
	cin >> S;
	int n = S.size();
	puts(S.substr(0, min(4, n)) == "YAKI" ? "Yes" : "No");
}
//--------------8---------------->> coding space <<-----------------8-------------//

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()
#define fast ios::sync_with_stdio(0); cin.tie(0)
#define int long long
const int mod = 1e9+7;  
int power(int a,int b) { if(b==0) return 1; int res = power(a,b/2); if(b&1) return res * res * a; else return res * res; }


int32_t main(){
    
  fast;
  int n; cin >> n;
  int ar[n];
  int prefix[n] = {0};

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

  prefix[0] = ar[0];

  for(int i=1;i<n;i++){
    prefix[i] = prefix[i-1] + ar[i];
  }

  int minn = 1e18;

  for(int i=0;i<n-1;i++){
    int left = prefix[i];
    int right = prefix[n-1] - prefix[i];
    minn = min(minn,abs(left-right));
  }

  cout << minn << '\n';

  return 0;
}

Measured memory_bytes: 3328
#include<iostream>
#include<algorithm>
#include<set>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    int a[n];
    int m[200000+2]={};
    set<int> s;
    
    for(int i=0;i<n;i++){
        cin >> a[i];
        m[a[i]]++;
        s.insert(a[i]);
    }
    sort(m,m+200000+2);
    int ans=0;
    int cnt=0;
    for(int i=0;i<200000+2;i++){
        if(m[i]!=0&&s.size()>k){
            cnt++;
            ans+=m[i];
            if(s.size()-cnt<=k) break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 11136
words = ["dream", "dreamer", "erase", "eraser"]
s = input()

s = s[::-1]
for i in range(len(words)):
    words[i] = words[i][::-1]

count = 0
while True:
    if s[count:count+5] == words[0]:
        count += 5
    elif s[count:count+7] == words[1]:
        count += 7
    elif s[count:count+5] == words[2]:
        count += 5
    elif s[count:count+6] == words[3]:
        count += 6
    else:
        ans = "NO"
        break
    if count == len(s):
        ans = "YES"
        break
print(ans)


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

int n;
long long arr[3005];
long long DP[3005][3005][2];

long long dp(int L, int R, int turn){
	if(L>R) return 0;
	if(DP[L][R][turn]!=-1) return DP[L][R][turn];
	
	if(turn == 1){
		long long x1 = arr[L] + dp(L+1,R,0);
		long long x2 = arr[R] + dp(L,R-1,0);
		return DP[L][R][turn]  = max(x1,x2);
	} else {
		long long x1 = dp(L+1,R,1);
		long long x2 = dp(L,R-1,1);
		return DP[L][R][turn]  = min(x1,x2);
	}
}

int main(){
	memset(DP,-1,sizeof DP);
	scanf("%d",&n);
	long long tot =0;
	for (int i = 0; i<n;i++){
		scanf("%lld",&arr[i]);
		tot += arr[i];
	}
	long long ans = dp(0,n-1,1);
	printf("%lld\n", ans-(tot-ans));
	return 0;
}

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

int main(){
    int n,h[100],ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int left=0,right;
    while(left<n){
        if(h[left]==0){
            left++;
            continue;
        }
        for(right=left;right<n;right++){
            if(h[right]>0){
                h[right]--;
            }else{
                ans++;
                break;
            }
        }
        if(right==n)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 384
from sys import stdin                                                                                                                                                                                                                
                                                                                                                                                                                                                                     
h, w = [int(x) for x in stdin.readline().rstrip().split()]                                                                                                                                                                           
                                                                                                                                                                                                                                     
a = []                                                                                                                                                                                                                               
for _ in range(h):                                                                                                                                                                                                                   
    i = list(input())                                                                                                                                                                                                                
    if "#" in i:                                                                                                                                                                                                                     
        a.append(i)                                                                                                                                                                                                                  
ans = zip(*[x for x in zip(*a) if "#" in x])                                                                                                                                                                                         
for s in ans:                                                                                                                                                                                                                        
    print(*s, sep="")         

Measured memory_bytes: 4596
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int n = scanner.nextInt();
        int[] p = new int[n];
        Arrays.setAll(p, i -> scanner.nextInt());
        int count = 0;
        for (int i = 1; i < n - 1; i++) {
            if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || p[i - 1] > p[i] && p[i] > p[i + 1]) {
                count++;
            }
        }
        System.out.println(count);
    }
}

Measured memory_bytes: 27860
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<stack>
#include<stdlib.h>
#include<queue>
#include<vector>
#include<list>
using namespace std;
int main ()
{
    for(int i=1;i<=9;i++)
        for(int j=1;j<=9;j++)
    {
        printf("%dx%d=%d\n",i,j,i*j);
    }
    return 0;
}




Measured memory_bytes: 3108
n = int(input())
*a, = map(int, input().split())
a = [0] + a + [0]
S = sum(abs(i-j) for i, j in zip(a, a[1:]))
for i in range(1, n+1):
    s = S + abs(a[i-1]-a[i+1]) - (abs(a[i-1] - a[i]) + abs(a[i] - a[i+1]))
    print(s)


Measured memory_bytes: 20488
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int f(int x){
    return (x * (1 + x)) / 2;
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        if (f(i) >= n){
            int ans = i;
            while(n > ans){
                cout << ans << endl;
                n -= ans;
                ans--;
            }
            cout << n << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3644
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#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 rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#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) REP(i, vec.size()) cerr<<vec[i]<<(i==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    ll i=1, ans = HIGHINF;
    while (i*i<=n) {
        if (n%i==0) {
            chmin(ans, i-1 + (n/i)-1);
        }
        i++;
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 384
N=int(input())
A=[]
for i in range(0,N):
    A.append(int(input()))

ans=0
for i in range(0,N-1):
    if A[i]>i:
        print(-1)
        break
    else:
        if A[i+1]>A[i]:
            if A[i+1]-A[i]>=2:
                print(-1)
                break
        else:
            ans+=A[i]
else:

    if A[N-1]>N-1:
        print(-1)
    else:
        ans+=A[-1]
        print(ans)


Measured memory_bytes: 57612
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>


using namespace std;

// vector<vector<int>> mat(N, vector<int>(M, 0));

int main(int argc, const char *argv[])
{
    //ABC141 A
    string str;
    cin>>str;
    if(str == "Sunny")
    {
        cout<<"Cloudy";
    }
    else if(str == "Cloudy")
    {
        cout<<"Rainy";
    }
    else if (str == "Rainy")
    {
        cout<<"Sunny";
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = readInt();
        char[][] charMatrix = new char[N][N];

        for(int i=0; i<N; i++){
            String tmpStr = sc.next();
            for(int j=0; j<N; j++) {
                charMatrix[i][j] = tmpStr.charAt(j);
            }
        }

        long cnt = 0;

        for(int i=0; i<N; i++){
            char[][] shiftedMatrix = shiftCharMatrix(charMatrix, 0, i);

            if(checkCharMatrixSymmetry(shiftedMatrix)){
                cnt += N;
            }
        }

        System.out.println(cnt);
    }

    private static char[][] shiftCharMatrix(char[][] matrix, int H, int W) {
        int SIZE_H  = matrix.length;
        int SIZE_W = matrix[0].length;
        char[][] shiftedMatrix = new char[SIZE_H][SIZE_W];

        for(int h=0; h<SIZE_H; h++){
            for(int w=0; w<SIZE_W; w++){
                int next_h = (h + H) % SIZE_H;
                int next_w = (w + W) % SIZE_W;
                shiftedMatrix[next_h][next_w] = matrix[h][w];
            }
        }
        return shiftedMatrix;
    }

    private static boolean checkCharMatrixSymmetry(char[][] matrix){
        int N = matrix.length;
        for(int i=0; i< N; i++){
            for(int j=i; j<N; j++){
                if(matrix[i][j] != matrix[j][i]){
                    return false;
                }
            }
        }

        return true;
    }

    private static char readChar(){
        return sc.next().charAt(0);
    }

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

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

}

Measured memory_bytes: 48936
#include <bits/stdc++.h>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

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

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

int main(){
    ll n; cin>>n;
    vector<ll> a(n);
    ll sum=0, nsum=n*(n+1)/2;
    for(int i=0; i<n; i++){
        cin>>a[i];
        sum+=a[i];
    }

    if(sum%nsum!=0){
        cout << "NO" << endl;
        return 0;
    }

    ll cnt=sum/nsum, dsum=0;
    vector<ll> d(n);
    for(int i=0; i<n; i++){
        d[i]=a[(i+1)%n]-a[i];
        d[i]-=cnt;
        if(d[i]%n==0) dsum+=abs(d[i]/n);
        else{
            cout << "NO" << endl;
            return 0;
        }
    }

    if(dsum==cnt){
        cout << "YES" << endl;
    }
    else{
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
/*
int dx[]={-1,1,0,0};
int dy[]={0,0,-1,1};
*/
#define ull unsigned long long int
#define ll long long int
#define MAX 1000000007
//1e9+7
#define pll pair<ll,ll>
#define pii pair<int,int>
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FO ifstream fin("a.in");ofstream fout("a.out");
#define TEST ll t;cin>>t;while(t--)
#define all(x) (x).begin(),(x).end()
#define mset0(x) memset((x), 0, sizeof((x)));
#define mset1(x) memset((x), -1, sizeof((x)));
typedef tree<ll,null_type,less<ll>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
void solve(){
    int n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    ll pre[n],suf[n];
    pre[0]=arr[0];
    for(int i=1;i<=n;i++){
        pre[i]=__gcd(pre[i-1],arr[i]);
    }
    suf[n-1]=arr[n-1];
    for(int i=n-2;i>=0;i--){
        suf[i]=__gcd(suf[i+1],arr[i]);
    }
    ll maxx=1;
    maxx=max(maxx,suf[1]);
    maxx=max(maxx,pre[n-2]);
    for(int i=1;i+1<n;i++){
        maxx=max(maxx,__gcd(suf[i+1],pre[i-1]));
    }
    cout<<maxx;
}
int main(){
    IO
    solve();
    return(0);
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000

using Point = complex<double>;
const double EPS = 1e-8;
#define X real()
#define Y imag()
namespace std {
  bool operator<(const Point a, const Point b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
}

// ?????? dot(a,b) = |a||b|cos??
double dot(Point a, Point b){ return a.X*b.X + a.Y*b.Y; }
// ?????? cross(a,b) = |a||b|sin??
double cross(Point a, Point b){ return a.X*b.Y - a.Y*b.X; }

// AB ???????????? AC???????????????????????????
int ccw(Point a, Point b, Point c){
  b -= a;  c -= a;
  if (cross(b,c) >  EPS) return +1;  // ccw
  if (cross(b,c) < -EPS) return -1;  // ccw
  if (dot(b,c)   < -EPS) return +2;  // c--a--b on line
  if (norm(b) < norm(c)) return -2;  // a--b--c on line or a==b
  return 0;                          // a--c--b on line or a==c or b==c
}

bool isecSP(Point a1, Point a2, Point b){
  return !ccw(a1, a2, b);
}
bool isecSS(Point a1, Point a2, Point b1, Point b2){
  return ccw(a1, a2, b1)*ccw(a1, a2, b2) <= 0 && ccw(b1, b2, a1)*ccw(b1, b2, a2) <= 0;
}

// ???p?????´???a1-a2???????°???±???
Point proj(Point a1, Point a2, Point p){
  return a1 + dot(a2-a1, p-a1)/norm(a2-a1) * (a2-a1);
}

double distLP(Point a1, Point a2, Point p){
  return abs(proj(a1, a2, p) - p);
}

double distSP(Point a1, Point a2, Point p){
  Point r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}

double distSS(Point a1, Point a2, Point b1, Point b2) {
  if (isecSS(a1, a2, b1, b2)) return 0;
  return min(min(distSP(a1, a2, b1), distSP(a1, a2, b2)), min(distSP(b1, b2, a1), distSP(b1, b2, a2)));
}


int main(){
  int n;
  while(cin>>n, n){
    double sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    Point s(sx,sy), t(tx,ty);

    auto calc = [&](Point p1, Point p2, double h){
      double d = distSS(s, t, p1, p2);
      if(d <= h) return d;
      else return (h*h + d*d)/2.0/h;
    };

    double ans = 123456789;
    rep(_,n){
      double x[2],y[2],h;
      cin>>x[0]>>y[0]>>x[1]>>y[1]>>h;
      if(isecSS(s, t, Point(x[0],y[0]), Point(x[1],y[1])) ||
         isecSS(s, t, Point(x[0],y[1]), Point(x[1],y[0])) ){
        ans = 0;
        continue;
      }
      vector<Point> v;
      rep(i,2)rep(j,2) v.pb(Point(x[i],y[j]));
      swap(v[2],v[3]);
      v.pb(v[0]);

      rep(i,4){
        ans = min(ans, calc(v[i], v[i+1], h));
      }
    }

    printf("%.9f\n", ans);
  }

  return 0;
}

Measured memory_bytes: 3272
#include<stdio.h>
#include<stdlib.h>

typedef long long int int64;

int popcnt(int n){
  unsigned int s=(unsigned int)n;
  s=(s&0x55555555)+((s&0xAAAAAAAA)>>1);
  s=(s&0x33333333)+((s&0xCCCCCCCC)>>2);
  s=(s&0x0F0F0F0F)+((s&0xF0F0F0F0)>>4);
  s=(s&0x00FF00FF)+((s&0xFF00FF00)>>8);
  s=(s&0x0000FFFF)+((s&0xFFFF0000)>>16);
  return s;
}

void run(void){
  const int mod=1000000000+7;
  int n;
  scanf("%d",&n);
  int *a=(int *)calloc(n*n,sizeof(int));
  int i;
  for(i=0;i<n*n;i++) scanf("%d",a+i);
  int64 *dp=(int64 *)calloc(1<<n,sizeof(int64));
  dp[0]=1;
  for(i=1;i<(1<<n)-1;i++){
    int k=popcnt(i)-1;
    int64 local=0;
    int j;
    for(j=0;(1<<j)<=i;j++){
      if(((i>>j)&1)==0 || !a[k*n+j]) continue;
      local+=dp[i^(1<<j)];
    }
    dp[i]=local;
  }
  int ans=0;
  for(i=0;i<n;i++){
    if(a[(n-1)*n+i]){
      ans=(ans+dp[((1<<n)-1)^(1<<i)])%mod;
    }
  }
  printf("%d\n",ans);
}

int main(void){
  run();
  return 0;
}


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

using namespace std;

const int INF = 1e9;

int n,m,i,j,k,dp[2][(1 << 15) + 5][16],cost[(1 << 15) + 5][16],edge[16][16];

void precompute(){
	for(i = 0; i < (1 << n); i++){
		for(j = 0; j < n; j++){
			if(i & (1 << j)) continue;
			
			for(int k = 0; k < n; k++){
				if((i & (1 << k)) == 0) continue;
				if(edge[j][k] == INF) continue;
				
				cost[i][j] += edge[j][k];
			}
		}
	}
}

void solve(int x, int y, int lv, int cur, int p){
	if(lv == n){
		dp[1][cur][y] = min(dp[1][cur][y], dp[0][x][y] + p);
		return;
	}
	
	solve(x, y, lv + 1, cur, p);
	if((x & (1 << lv)) == 0)
	solve(x, y, lv + 1, cur | (1 << lv), p + cost[x ^ (1 << y)][lv]);
}

int main(){
	scanf("%d%d", &n, &m);
	
	for(i = 0; i < n; i++){
		for(j = 0; j < n; j++)
		edge[i][j] = INF;
	}
	
	for(i = 0; i < m; i++){
		int x,y,z;
		scanf("%d%d%d", &x, &y, &z);
		x--;
		y--;
		edge[x][y] = z;
		edge[y][x] = z;
	}
	
	precompute();
	
	for(i = 0; i < (1 << n); i++){
		for(j = 0; j < n; j++){
			dp[0][i][j] = INF;
			dp[1][i][j] = INF;
		}
	}
	
	dp[0][1][0] = 0;
	
	for(i = 0; i < (1 << n); i++){
		for(j = 0; j < n; j++){
			if((i & (1 << j)) == 0) continue;
			//0 -> 0
			//1 -> 0
			
			for(k = 0; k < n; k++){
				if(i & (1 << k)) continue;
				if(edge[j][k] == INF) continue;
				
				dp[0][i | (1 << k)][k] = min(dp[0][i | (1 << k)][k], dp[0][i][j] + cost[i][k] - edge[j][k]);
				dp[0][i | (1 << k)][k] = min(dp[0][i | (1 << k)][k], dp[1][i][j] + cost[i][k] - edge[j][k]);
			}
			
			//0 -> 1
			//printf(">> %d %d %d %d\n", i, j, dp[0][i][j], dp[1][i][j]);
			solve(i, j, 0, i, 0);
		}
	}
	
	printf("%d\n",  min(dp[0][(1 << n) - 1][n - 1], dp[1][(1 << n) - 1][n - 1]));
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], n, m, v[N];
long long cnt[N][2];
vector<int> G[N];
int p1, p2, len;
long long dfs(int x, int p = 0, int d = 0) {
	++ cnt[x][d & 1];
	long long res = 0;
	for (int u : G[x]) {
		if (u == p) continue;
		if (x == p1 && u == p2) continue;
		if (x == p2 && u == p1) continue;
		res += dfs(u, x, d + 1);
		cnt[x][0] += cnt[u][0];
		cnt[x][1] += cnt[u][1];
		res += abs(cnt[u][0] - cnt[u][1]);
	}
	return res;
}
void dfs2(int x, int p = 0) {
	v[x] = v[p] + 1;
	for (int u : G[x]) {
		if (u == p) continue;
		if (v[u]) {
			p1 = x;
			p2 = u;
			len = v[x] - v[u] + 1;
		}
		else dfs2(u, x);
	}
}
long long calc(long long x) {
	memset(cnt, 0, sizeof(cnt));
	cnt[p1][0] += x;
	cnt[p2][0] -= x;
	return dfs(1) + abs(x);
}
int main() {
	scanf("%d%d", &n, &m);
	for (int i = 0; i < m; ++ i) {
		int u, v;
		scanf("%d%d", &u, &v);
		a[i] = u, b[i] = v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	if (m == n - 1) {
		long long ans = dfs(1);
		if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
		printf("%lld\n", ans);
	}
	else {
		dfs2(1);
		dfs(1);
		if (len & 1) {
			if (abs(cnt[1][0] - cnt[1][1]) & 1) return 0 * puts("-1");
			long long del = (cnt[1][0] - cnt[1][1]) / 2;
			memset(cnt, 0, sizeof(cnt));
			cnt[p1][0] -= del;
			cnt[p2][0] -= del;
			long long ans = dfs(1) + abs(del);
			printf("%lld\n", ans);
		}
		else {
			if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
			long long l = - 1e9, r = 1e9, ans = 1e18;
			while (l + 10 <= r) {
				long long midl = (l + r) / 2;
				long long midr = (midl + r) / 2;
				long long res1 = calc(midl);
				long long res2 = calc(midr);
				ans = min(ans, res1);
				ans = min(ans, res2);
				if (res1 < res2) {
					r = midr - 1;
				}
				else {
					l = midl + 1;
				}
			}
			for (int i = l; i <= r; ++ i) ans = min(ans, calc(i));
			printf("%lld\n", ans);
		}
	}
}



Measured memory_bytes: 16256
import java.util.Scanner;

public class Main {

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

		int minCost = 1001;

		int N = sc.nextInt();
		int T = sc.nextInt();

		int c;int t;
		for (int i=0;i<N;i++) {
			c = sc.nextInt();
			t = sc.nextInt();
			if (t<=T) {
				if (c<=minCost) {
					minCost = c;
				}
			}
		}

		if (minCost==1001) {
			System.out.println("TLE");
		} else {
			System.out.println(minCost);
		}

	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline

INF = 10 ** 9
MOD = 10 **9 + 7

N = int(input())

C = [int(input()) for _ in range(N)]
lst = [INF] * (2 * 10 ** 5 + 10) #各番号がどこにあるかを管理するリスト
ans = [1] * N
 
lst[C[-1]] = N - 1

for i in range(N - 2, -1, -1):
    c = C[i]
    if lst[c] == INF or lst[c] == i + 1:
        ans[i] = ans[i + 1]
    else:
        ans[i] = ans[i + 1] + ans[lst[c]]
    lst[c] = i

# print (ans)
print (ans[0] % MOD)

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

using ll = long long;
using pp = pair<ll,ll>;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)
//fixed << setprecision(20)

int main(){
	int n,m;
	cin >> n >> m;
	ll b;
	priority_queue<ll> a;
	for(int i = 0; i < n; i++){
		cin >> b;
		a.push(b);
	}
	while(m > 0){
		b = a.top();
		a.pop();
		b /= 2;
		a.push(b);
		m--;
	}
	ll sum = 0;
	for(int i = 0; i < n; i++){
		sum += a.top();
		a.pop();
	}
	cout << sum << endl;
	return 0;
}
 

Measured memory_bytes: 1400
//Date:06-01-17
 
#include<stdio.h>
#include<string.h>
#include<assert.h>
#include<stdlib.h>
#include<stdbool.h>
#include<float.h>
#include<math.h>
#include<ctype.h>
#include<limits.h>
#include<time.h>
#define ll long long
#define For(i,n)	for(i=0;i<n;i++)
#define rep(i ,a ,b)	for(i=(a);i<=(b);i++)
#define mset(a ,value)	memset(a ,value ,sizeof(a))
#define s(a)	scanf("%d" ,&a);
#define ls(a)	scanf("%ld" ,&a)
#define reg(i)	register int i
#define infinite INT_MAX
#define MAX 100005
#define NIL -1
int min(int a,int b){	return (a<b?a:b);	}
int max(int a,int b){	return (a>b?a:b);	}
main(){
	char s[20];
	scanf("%s" ,s);
	int i;
	For(i ,19){
		if(s[i]==',')	printf(" ");
		else printf("%c" ,s[i]);
	}
	return 0;
}

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

using namespace std;

int main() {
  long long n;
  cin >> n;
  string s, t = "abcdefghijklmnopqrstuvwxyz";
  while (n) {
  	n--;
    s += t[n % 26];
    n /= 26;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}

Measured memory_bytes: 3628
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = GL();
		var x = I[0];
		var y = I[1];
		var c = 0;
		while (x <= y)
		{
			c++;
			x *= 2;
		}
		Console.WriteLine(c);
	}
}


Measured memory_bytes: 13268
N = int(input())
H = list(map(int,input().split()))

H[0] -= 1
fl = True
for i in range(1, N):
    if H[i-1] > H[i]:
        fl = False
        break
    elif H[i-1] < H[i]:
        H[i] -= 1    

print("Yes" if fl else "No")

Measured memory_bytes: 63984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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 all(x) (x).begin(),(x).end()
#define pll pair<ll,ll>
#define pii pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define For(i,a,b) for(int i=a;i<b;i++)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define mp make_pair
#define bit(n) (1LL<<(n))
#define F first
#define S second
#define debug(x) cerr << x << endl
#define Complex complex<double>
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll INF = 1LL<<60;
const ll mod = (int)1e9 + 7;

int main() {
    int n;
    cin >> n;
    rep(i,n){
        int x;
        cin >> x;
        if(x%2)continue;
        if(x%3 && x%5){
            cout << "DENIED";
            return 0;
        }
    }
    cout << "APPROVED";


    
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>
#include <cstring>


int main() {
    int n; std::cin >> n;
    std::vector<int> ans(n + 1);
    for (int x = 1; x <= 100; x++) {
        for (int y = 1; y <= 100; y++) {
            for (int z = 1; z <= 100; z++) {
                int t = x*x + y*y + z*z + x*y + y*z + z*x;
                if (t <= n) ans[t]++;
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        std::cout << ans[i] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3488
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

vector<long long> f(long long N){
    vector<long long> ret;
    for(int k=1;k<=40;++k){
        long long X=(1LL<<k);
        long long Y=(1LL<<(k-1));
        ret.push_back(N/X*Y+max(0LL,(N%X)-Y));
    }
    return ret;
}

int main() {
    long long a,b;
    cin>>a>>b;
    vector<long long> m[2]={f(b+1),f(a)};
    long long ans=0;
    for(int i=0;i<40;++i){
        long long x=m[0][i]-m[1][i];
        if(x%2)ans^=(1LL<<i);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N := nextInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = nextInt()
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans += A[i] - 1
	}

	fmt.Println(ans)

}


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

using namespace std;

typedef long long int64;

int main()
{
  int64 N, A, B, X[100000];

  cin >> N >> A >> B;
  for(int i = 0; i < N; i++) cin >> X[i];

  int64 ret = 0;
  for(int i = 1; i < N; i++) {
    int64 odd = (X[i] - X[i - 1]) * A;
    int64 warp = B;
    ret += min(odd, warp);
  }
  cout << ret << endl;
}





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

using ll = long long;
const ll amari = 1e9+7;
const char BC = 'A' - 'a';
#define ben(a) a.begin(),a.end()
#define pb(a,b) a.push_back(b)

int main(){
	int n,a;
	string s;
	cin >> n >> a >> s;
	s[a - 1] = s[a - 1] - BC;
	cout << s << endl;
	return 0; 
}


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

using namespace std;

int d[10][10];

int main()
{
	for(;;){
		int n, t_cont = 0, best_t = -1;
		int from, to, cost, cont = 0;
		int Min = 1000000000;
		bool isUsed[11] = {0};
		
		
		//INFツづ渉可甘コツ可サ
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				d[i][j] = 100000;
				if(i == j){
					d[i][j] = d[j][i] = 0;
				}
			}
		}
		
		cin >> n;
		if(n == 0){
			break;
		}
		
		for(int i = 0; i < n; i++){
			cin >> from >> to >> cost;
			d[from][to] = d[to][from] = cost;
			isUsed[from] = 1;
			isUsed[to] = 1;
		}
		
		for(int i = 0; i < 11; i++){
			if(isUsed[i] == 1){
				t_cont++;
			}
		}
		
	//	cout << t_cont << endl;
		
		//ツδ渉ーツシツδδδ仰づ猟ャツつキ
		
		for(int k = 0; k < t_cont; k++){
			for(int i = 0; i < t_cont; i++){
				for(int j = 0; j < t_cont; j++){
					d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
				}
			}
		}
		/*
		for(int i = 0; i < 10; i++){
			for(int j = 0; j < 10; j++){
				printf("%d   ",d[i][j]);
			}
			cout << endl;
		}
		*/
		//ツ全ツ閉板個ゥツづゥ
		for(int i = 0; i < t_cont; i++){
			for(int j = 0; j < t_cont; j++){
				cont += d[i][j];
			}
			if(cont < Min){
				Min = cont;
				best_t = i;
			}
			cont = 0;
		}
		
		cout << best_t << " " << Min << endl;
	}
}

Measured memory_bytes: 0
#include <stdio.h>
#include <stdlib.h>

int n, m;

void merge(int *u, int *net, int oldnet, int newnet);

int main(int argc, char *argv[])
{
  int i, s, t, p, q;
  int *u;
  int *net;

  scanf("%d", &n);
  scanf("%d", &m);
  u = (int *)malloc(sizeof(int) * n);
  net = (int *)malloc(sizeof(int) * (m + 1));
  for (i = 0; i < n; i++) u[i] = -1;
  for (i = 0; i <= m; i++) net[i] = 0;

  p = 1;

  for (i = 0; i < m; i++) {
    scanf("%d", &s);
    scanf("%d", &t);
    if (s != t) {
      if (u[s] == -1 && u[t] == -1) {
	u[s] = p;
	u[t] = p;
	net[p] += 2;
	p++;
      } else {
	if (u[s] != -1 && u[t] == -1) {
	  u[t] = u[s];
	  net[u[s]]++;
	} else if (u[s] == -1 && u[t] != -1) {
	  u[s] = u[t];
	  net[u[t]]++;
	} else {
	  if (u[s] != u[t]) {
	    if (net[u[s]] > net[u[t]]) merge(u, net, u[t], u[s]);
	    else merge(u, net, u[s], u[t]);
	  }
	}
      }
    }
  }

  scanf("%d", &q);

  for (i = 0; i < q; i++) {
    scanf("%d", &s);
    scanf("%d", &t);

    if (s == t) printf("yes\n");
    else {
      if (u[s] == u[t] && u[s] != -1 && u[t] != -1) printf("yes\n");
      else printf("no\n");
    }
  }

  return 0;
}

void merge(int *u, int *net, int oldnet, int newnet)
{
  int i;
  
  for (i = 0; i < n; i++) {
    if (u[i] == oldnet) u[i] = newnet;
  }

  net[newnet] += net[oldnet];
  net[oldnet] = 0;
}

Measured memory_bytes: 1368
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        if(k <= a) {
            System.out.println(k);
        } else if(k <= a + b) {
            System.out.println(a);
        } else {
            System.out.println(a - (k - a -b ));
        }
    }
}

Measured memory_bytes: 26908
#include<bits/stdc++.h>
#include<iomanip>
#include<cmath>
const double pi=3.14159265359;
using namespace std;


int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  double a,b,h,m;
  cin>>a>>b>>h>>m;
  double d=h*60+m;
  int p=(d*5.5)/360;
  double l=d*5.5-p*360;
  double x=min(l,360-l);
  double y=(x/180.0)*pi;
  double c=sqrt(a*a+b*b-2*a*b*cos(y));
  cout<<setprecision(12)<<c<<endl;


  
  

}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(int x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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;
};

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

  ll A, B;
  cin >> A >> B;
  ll g = __gcd(A, B);
  cout << A / g * B << endl;

  return 0;
};


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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >
# define PQ priority_queue

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvs vector < vs >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";
int month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.1415926535897932384626 ;
const ll mod = 1e9 + 7 ;

/// Tip : If a and b are positive integers ; we may say - ceil (a/b) = 1 + floor ( (a-1)/b ) .

void solve ( int test_case )
{
    ll n , k ;
    cin >> n >> k ;

    ll ans = n ;

    n %= k ;
    ans = min ( ans , n ) ;

    n = abs ( n - k ) ;
    ans = min ( n , ans ) ;

    cout << ans ; line ;
}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=1 ; i <= t ; i ++ ) solve ( i ) ;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
vector<int> adj[MAX];
bool vis[MAX];
void dfs(int src){
    vis[src] = true;
    for(int nxt: adj[src]){
        if(vis[nxt]) continue;
        dfs(nxt);
    }
}
int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vector<int> a(n), b(n);
    int val = 0;
    for(int i = 0; i < n; i++) cin >> a[i], val ^= a[i];
    for(int i = 0; i < n; i++) cin >> b[i];
    vector<int> check_a, check_b;
    for(int i = 0; i < n; i++) check_a.push_back(a[i]);
    check_a.push_back(val);
    for(int i = 0; i < n; i++) check_b.push_back(b[i]);
    sort(check_a.begin(), check_a.end());
    sort(check_b.begin(), check_b.end());
    int it1 = 0, it2 = 0;
    int skip = -1;
    while(it1 != n + 1 && it2 != n){
        while(it1 <= n && check_a[it1] != check_b[it2]) skip = check_a[it1], it1++;
        if(it1 == n + 1 || check_a[it1] != check_b[it2]) break;
        it1++, it2++;
    }
    if(it2 != n){
        cout << -1 << '\n';
        return 0;
    }
    if(skip == -1) skip = check_a.back();
    vector<pair<int, int>> use;
    for(int i = 0; i < n; i++){
        if(a[i] == b[i]) continue;
        use.emplace_back(a[i], b[i]);
    }
    use.emplace_back(val, skip);
    if((int) use.size() == 1){
        cout << 0 << '\n';
        return 0;
    }
    reverse(use.begin(), use.end());
    set<int> vert;
    for(auto e: use) vert.insert(e.first), vert.insert(e.second);
    map<int, int> conv;
    int cnt = 0;
    int num = 0;
    for(int x: vert) conv[x] = cnt, cnt++;
    for(int i = 1; i < (int) use.size(); i++){
        auto e = use[i];
        int u = conv[e.first], v = conv[e.second];
        adj[u].push_back(v); adj[v].push_back(u);
        num++;
    }
    int comp = 0;
    for(int i = 0; i < (int) vert.size(); i++){
        if(!vis[i]) dfs(i), comp++;
    }
    cout << (num + comp - 1) << '\n';
    return 0;
}


Measured memory_bytes: 23456
#include <iostream>
#include <math.h> 
#include <string> 
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;

int main() {

	int N; cin >> N;
	int a[10000]; for (int i = 1; i <= N; i++) cin >> a[i];
	int res = 0;

	for (int i = 1; i <= N; i++) res += (a[i] - 1) ;

	cout << res << endl;
}

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

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))

#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)

#define nl '\n'
#define ioi exit(0);


#define PI 3.14159265

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

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
//~ const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
  
int main() 
{ 
	int n; cin>> n;
	long long sum = 0;
	for(int i = 1; i <= n; i++){
		if(i % 3 == 0 && i % 5 == 0)
			continue;
		else if(i % 3 == 0)
			continue;
		else if(i % 5 == 0)
			continue;
		else
			sum += i;
	}
	cout<< sum;
	return 0;
} 




Measured memory_bytes: 3632
package main

import "fmt"

func main() {
	var n, m int
	fmt.Scanf("%d %d", &n, &m)

	a := make([][]int, n)
	b := make([][]int, m)
	c := make([][]int, n)

	for i := 0; i < n; i++ {
		a[i] = make([]int, m)
		for j := 0; j < m; j++ {
			fmt.Scanf("%d", &a[i][j])
		}
	}
	for j := 0; j < m; j++ {
		b[j] = make([]int, 1)
		for k := 0; k < 1; k++ {
			fmt.Scanf("%d", &b[j][k])
		}
	}
	for i := 0; i < n; i++ {
		c[i] = make([]int, 1)
		for k := 0; k < 1; k++ {
			for j := 0; j < m; j++ {
				c[i][k] += a[i][j] * b[j][k]
			}
		}
	}
	for i := 0; i < n; i++ {
		fmt.Println(c[i][0])
	}
}



Measured memory_bytes: 1764
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,n,g) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n; string s;
  cin >> n >> s;
  string a = "abcdefghijklmnopqrstuvwxyz";
  int ans = 0;
  rep(i,0,n-1) {
    int p = 0;
    rep(k,0,26) {
      bool fx = false,fy = false;
      rep(j,0,i) if (s[j] == a[k]) fx = true;
      rep(j,i,n) if (s[j] == a[k]) fy = true;
      if (fx && fy) p++;
    }
    ans = max(ans,p);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3620
N=int(input())
a=list(map(int, input().split()))

if N==2:
  print(a[1], a[0])
  exit()
  
ans=[0]*N
tmp=a[1]^a[2]
for i in range(3, N):
  tmp=tmp^a[i]
  
ans[0]=tmp
for i in range(1, N):
  tmp=a[i-1]^a[i]
  ans[i]=tmp^ans[i-1]
  
print(*ans, sep=' ')

Measured memory_bytes: 31532