akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
long long gcd(long x,long y){
    if(y==0)return x;

    return gcd(y,x%y);
}
long long lcm(long x,long y){
    return x*y/gcd(x,y);
}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

double l(int x1,int y1,int x2,int y2){
    int dx = x1-x2;
    int dy = y1-y2;

    return pow(dx*dx + dy*dy,0.5);

}

int main()
{
    int N,x[10]={},y[10]={};
    vector<int> v;
    long long cnt=0;
    double sum=0,ans;
    cin>>N;
    for(int i=1;i<=N;i++){
        cin>>x[i]>>y[i];
        v.push_back(i);
    }

    do {
        for(int i=0;i<N-1;i++){
            sum+=l(x[v[i]],y[v[i]],x[v[i+1]],y[v[i+1]]);
        }
        cnt++;
    } while (std::next_permutation(v.begin(), v.end()));

    ans = (double)sum/cnt;

    cout<<setprecision(10)<<fixed;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

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

#define F first
#define S second

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> llll;
typedef pair<int, ii> iii;
typedef vector<ii> vii;
typedef vector<ll> vll;
typedef vector<llll> vllll;
typedef vector<int> vi;
typedef vector<ull> vull;

// TIMER
std::clock_t __start;
double __duration;
void start_timer() { __start = std::clock(); }
void print_timer() {
	__duration = (std::clock() - __start) / (double)CLOCKS_PER_SEC;
	std::cout << "Duration (msec): " << __duration * 1000 << '\n';
}
// END TIMER

//PI
# define M_PI		3.14159265358979323846
// fast input
#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
//char _;

template <class T>
T min_(T a, T b) { return (a < b ? a : b); }
template <class T>
T max_(T a, T b) { return (a > b ? a : b); }
double EPS = 1e-9;
bool eq_(const double& lhs, const double &rhs) {
	return (fabs(lhs - rhs) < EPS);
}

const int INF = int(2e9);
const ll INF_LL = LLONG_MAX;


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll A, B, C;
	cin >> A >> B >> C;
	ll res;
	if (A % 2 == 0 || B % 2 == 0 || C % 2 == 0) {
		res = 0;
	}
	else {
		vll nums = { A, B, C };
		sort(nums.begin(), nums.end());
		res = nums[0] * nums[1];
	}
	cout << res << '\n';
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a =0;
  int b =0;
  int c =0;
  scanf("%d %d %d", &a , &b , &c);
  if(a<b && b<c){
    printf("Yes\n");
  }
  else {
    printf("No\n");
  }
  return 0;
}
  



Measured memory_bytes: 2024
N = int(input())
A = [int(x) for x in input().split()]

abs_list = sorted([abs(x) for x in A])[::-1]

for i in range(N-1):
    if A[i] < 0:
        A[i] *= -1
        A[i+1] *= -1

if abs(min(A)) != min(abs_list):
    A[A.index(min(A))] *= -1
    A[A.index(min(abs_list))] *= -1
    
print(sum(A))

Measured memory_bytes: 14412
#include<iostream>
#include<cstring>
using namespace std;
int H,W;
char map[110][110];
int dir[4][2] = {{0,1},{0,-1},{-1,0},{1,0}};

int res;

bool InBox(int nx,int ny)
{
	return nx>=0&&nx<W&&ny>=0&&ny<H;
	
}

void dfs(int x,int y,char c)
{
	map[y][x] = '.';
	for(int i=0;i<4;i++)
	  {
	  	int nx = x+dir[i][0];
	  	int ny = y+dir[i][1];
	  	if(InBox(nx,ny)&&map[ny][nx]==c)
	  	  dfs(nx,ny,c);
	  }
	  
	
	
}

int main()
{
	cin>>H>>W;
	while(H&&W)
	{
		res=0;
		memset(map,0,sizeof(map));
		
		
		for(int y=0;y<H;y++)
		  for(int x=0;x<W;x++)
		    cin>>map[y][x];
		    
		for(int y=0;y<H;y++)
		  for(int x=0;x<W;x++)
		    if(map[y][x]!='.'){
		      dfs(x,y,map[y][x]);
		      res++;
			}
		      
		cout<<res<<endl;
		cin>>H>>W;
		
	}
}


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

bool marked[(int)1e6];
void sieve()
{
    memset(marked, true, sizeof(marked));
    for(long long i = 2; i * i < (int)1e6; i++)
    {
        if(marked[i] == true)
        {
            for(long long j = i * i; j < (int)1e6; j += i)
            {
                marked[j] = false;
            }
        }
    }
}

int main()
{
    sieve();
    int x;
    cin >> x;
    while(marked[x] == false)
        x++;
    cout << x << endl;
}


Measured memory_bytes: 4600
a,b = gets.split.map(&:to_i)
s = gets.chomp

def is_digit(s)
  s =~ /^\d+$/
end

befor = s[0, a]
after = s[a+1..-1]
if is_digit(befor) && is_digit(after) && s[a] == "-"
  puts "Yes"
else
  puts "No"
end


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

int main(){
    int n;
    cin >> n;
    int arr[n];
    int head = 0;
    int count=0;
    for(int i=0;i<n;i++){
        cin >> arr[i];
    }
    
    bool flag = true;
    while(flag){
        flag = false;
        for(int i=n-1;i>=head;i--){
            if(arr[i]<arr[i-1]){
                int tmp = arr[i];
                arr[i] = arr[i-1];
                arr[i-1] = tmp;
                flag=true;
                count++;
            }
        }
        head++;
        
    }

    for(int i=0;i<n;i++){
        cout << arr[i];
        if(i!=n-1)cout << " ";
    }
    cout << endl << count << endl;
    
}


Measured memory_bytes: 3084
#include <stdio.h>

int main(void) {
  int a, b, c, d, t;
  scanf("%d%d%d%d", &a, &b, &c, &d);
  t = a + b + c + d;
  printf("%d\n%d\n", t / 60, t % 60);
  return 0;
}


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


int main() {
    int n,k,ans=1;
    cin >>n>>k;
    while(1){
        if(n/k<=1 and n<k)break;else{
            n/=k;
            ans++;
        }
    }
    cout << ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
   int n,k,i,j;
   double p,pp;
    
   scanf("%d %d",&n,&k);
   p=0;
   for (i=1;i<=n;i++) {
      for (pp=1,j=i;j<k;j*=2) pp/=2;
      p+=pp;  
   }
   printf("%12.11f\n",p/n);
   return 0;
}


Measured memory_bytes: 128
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);

	static void solve() throws IOException{

		String s = in.next();
		char[][] cs = new char[3][3];

		for (int i=0; i<3; i++) {
			for (int j=0; j<3; j++) {
				cs[i][j] = s.charAt(i*3+j);
			}
		}

		if (isOk(cs,'o')) {
			out.println('o');
		} else if (isOk(cs,'x')) {
			out.println('x');
		} else {
			out.println('d');
		}
	}

	static boolean isOk(char[][] cs, char c) {

		for (int i=0; i<3; i++) {
			boolean f1 = true;
			boolean f2 = true;
			for (int j=0; j<3; j++) {
				if (cs[i][j] != c) f1 = false;
				if (cs[j][i] != c) f2 = false;
			}
			if (f1) return true;
			if (f2) return true;
		}

		return (cs[0][0] == c && cs[0][0] == cs[1][1] && cs[1][1] == cs[2][2]) || (cs[0][2] == c && cs[0][2] == cs[1][1] && cs[1][1] == cs[2][0]);
	}

	public static void main(String[] args) throws Exception {
		long start = System.currentTimeMillis();

		while(in.hasNext()) solve();
		out.flush();

		long end = System.currentTimeMillis();
		//trace(end-start + "ms");
		in.close();
		out.close();
	}

	static void trace(Object... o) { System.out.println(Arrays.deepToString(o));}
}

Measured memory_bytes: 26152
//
// Created by mustafa on 05/07/19.
//
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std ;

#define ll long long
#define submitStage int TCF = 1 ;
#define testStage int TCF = 1000 ;
#define Start while(TCF--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define FORd(i, a, b) for (int i = (a); i >= (b); i--)
#define REP(i, n) FOR(i, 0, n)
#define FastInputOutput ios_base :: sync_with_stdio( 0 ) ; cin.tie( 0 ) ; cout.tie( 0 ) ;
#define ReadFromFile(x)  freopen( x, "rt" , stdin ) ;
#define WriteToFile(x)  freopen( "in.txt", "wt" , stdout ) ;
#define D(x) scanf("%d",&x);
#define LLD(X) scanf("%lld",&x);
#define in(x,...) scanf(x,__VA_ARGS__)
#define out(x,...) printf(x,__VA_ARGS__)
/// for debugging
string to_string(string s) {return '"' + s + '"';}string to_string(const char* s) {return to_string((string) s);}string to_string(bool b) {return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void debug_out() { cerr << endl; }template <typename Head, typename... Tail>void debug_out(Head H, Tail... T) {cerr << " " << to_string(H);debug_out(T...);}
#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) {}
#endif
/// start driven program
const int N = 2e4+5, M = 1e4, OO = 0x3f3f3f3f;

int main(){
    submitStage Start{
        // 1 , 5 , 10;
        int n,y;
        scanf("%d %d",&n , &y);
        y/=1000;
        int mx10=y/10 , mx5=0 , mx1=0;
        int t10 =0 , t5 =0 , t1=0;
        int a10=-1,a5=-1,a1=-1;
        bool get=true;
        for(int i=0 ; i <= mx10 & get; ++i){
            t10=y- (i*10);
            mx5=t10/5;
            for(int j=0 ; j <= mx5 & get ; ++j){
                t5=t10-(j*5);
                mx1=t5;
                if(i+j+mx1==n){
                    a10=i;
                    a5=j;
                    a1=mx1;
                    get=false;
                }
            }

        }
        printf("%d %d %d",a10,a5,a1);

    }
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : list(map(int, stdin.readline().split()))
sys.setrecursionlimit(10 ** 7)


def main():
  n = ni()
  s = ns()
  mid = n // 2
#   print(s[0:mid], s[mid:n])
  if s[0:mid] == s[mid:n]:
    print("Yes")
  else:
    print("No")

if __name__ == '__main__':
  main()


Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int D;
	cin >> D;

	bool ans = false;
	rep(i, 0, D / 4+1) {
		rep(j, 0, D / 7 + 1) {
			if (4 * i + 7 * j > D)continue;
			if (4 * i + 7 * j == D)ans = true;
		}
	}

	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;

}
	

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        
        int w = sc.nextInt();
        int n = sc.nextInt();

        int[] line = new int[w];

        for(int k = 0; k < w; k++){
            line[k] = k + 1;
        }

        for(int i = 0; i < n; i++){
            String str = sc.next();
            String[] ab = str.split(",");
            int a = Integer.parseInt(ab[0]);
            int b = Integer.parseInt(ab[1]);
            int t = line[a-1];
            line[a-1] = line[b-1];
            line[b-1] = t;
        }

        for(int j = 0; j < w; j++){
            System.out.println(line[j]);
        }

    }
}


Measured memory_bytes: 26092
#include <bits/stdc++.h>
using namespace std;
int main () {
  int a,b,c;
  cin >>a>>b>>c;
  if(a>b) swap(a,b);
  if(b>c) swap(b,c);
  if(a>b) swap(a,b);
  cout<<a<<" "<<b<<" "<<c<<endl;
  return 0;
}


Measured memory_bytes: 3028
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e16;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
  ll h, w;
  cin >> h >> w;
  ll n;
  cin >> n;
  vector <vector <ll>> v(h, vector <ll> (w));
  ll x = 0, y = 0, flag = 0;
  rep(i, n) {
    ll a;
    cin >> a;
    rep(j, a) {
      v.at(y).at(x) = i+1;
      if (flag%2 == 0) {
        if (x == w-1) {
          flag++;
          y++;
        } else {
          x++;
        }
      } else {
        if (x == 0) {
          flag++;
          y++;
        } else {
          x--;
        }
      }
    }
  }
  rep(i, h) {
    rep(j, w) {
      if (j) cout << ' ' << v.at(i).at(j);
      else cout << v.at(i).at(j);
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  R n;
  char c;
  set<char> s;
  rep(i,n) {
    cin >> c;
    s.in(c);
  }
  if(s.size()==3) pr("Three");
  else pr("Four");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

int main()
{
  int n; cin >> n;
  vector<pair<int,int>> v(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> v[i].first >> v[i].second;
  }
  bool ans = false;
  for(int i = 2; i < n; ++i)
  {
    bool flag = v[i-2].first == v[i-2].second;
    flag = flag and (v[i-1].first == v[i-1].second);
    flag = flag and (v[i].first == v[i].second);
    ans = ans or flag;
  }
  cout << (ans ? "Yes" : "No");
  return 0;
}

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

int l, i;
string s;

int main(){
    cin >> s;
    while(s.begin() != s.end()){
        switch(s[0]){
            case 'e':
                if(s.find("erase"))return 0 & puts("NO");
                if(s[5] == 'r')s.erase(s.begin(), s.begin() + 6);
                else s.erase(s.begin(), s.begin() + 5);
                break;
            case 'd':
                if(s.find("dream"))return 0 & puts("NO");
                s.erase(s.begin(), s.begin() + 5);
                if(s.begin() == s.end())return 0 & puts("YES");
                if(s.find("er") == 0 && s.find("erase") != 0){
                    s.erase(s.begin(), s.begin() + 2);
                }
                break;
            default:
                return 0 & puts("NO");
        }
    }
    puts("YES");
    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include <algorithm>
#include <iostream>
#include <functional>
#include<cmath>
#include<string.h>
#include<vector>
#include<queue>
#include<deque>

using namespace std;

int main(){
	int a,b,m,av[100009],bv[100009],c[100009][3],amin=999999,bmin=999999,min;
	scanf("%d %d %d",&a,&b,&m);
	for(int i=0;i<a;i++){
		scanf("%d",&av[i]);
		if(av[i]<amin){
			amin=av[i];
		}
	}
	for(int i=0;i<b;i++){
		scanf("%d",&bv[i]);
		if(bv[i]<bmin){
			bmin=bv[i];
		}
	}
	for(int i=0;i<m;i++){
		scanf("%d %d %d",&c[i][0],&c[i][1],&c[i][2]);
	}
	min = amin+bmin;
	
	for(int i=0;i<m;i++){
		amin = av[c[i][0]-1]+bv[c[i][1]-1]-c[i][2];
		if(min>amin) min=amin;
	}
	printf("%d\n",min);
	return 0;
}

Measured memory_bytes: 2176
#include <stdio.h>

int main()
{
  int a,b;

  scanf("%d %d", &a, &b);

  while(a != 0 && b != 0)
    {
      //     printf("%d %d\n", a, b);
      a > b ? (a = a%b) : (b = b%a);
    }
  printf("%d\n", a+b);

  return 0;
}

Measured memory_bytes: 592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

const int mod = 1000000007;

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> S(N), T(M);
    rep(i, N) cin >> S[i];
    rep(i, M) cin >> T[i];
    vector<vector<int>> dp(N + 1, vector<int>(M + 1, 1));
    rep(i, N) rep(j, M) {
        dp[i + 1][j + 1] = ((dp[i][j + 1] + dp[i + 1][j] - dp[i][j]) % mod + mod) % mod;
        if (S[i] == T[j]) dp[i + 1][j + 1] = (dp[i + 1][j + 1] + dp[i][j]) % mod;
    }
    cout << dp[N][M] << "\n";
    return 0;
}


Measured memory_bytes: 16000
n = int(input())
a = [int(i) for i in input().split()]
a.append(0)
cost = []

for i in range(n+1):
    if i == 0:
        cost.append(a[i])
    else:
        cost.append(a[i]-a[i-1])

sumcost = sum(map(abs,cost))

for i in range(n):
    ans = sumcost
    if cost[i] * cost[i+1] < 0:
        ans -= 2*min(abs(cost[i]),abs(cost[i+1]))
    print(ans)

Measured memory_bytes: 14048
#include <bits/stdc++.h>
using namespace std;
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    //ios::sync_with_stdio(false);
    //cin.tie(0);
    
    int N;
    while (cin >> N) {
        vector<int> a(N);
        for (int i = 0; i < N; ++i) cin >> a[i];

        bool exist_odd = false;
        for (int i = 0; i < N; ++i) if (a[i] % 2 == 1) exist_odd = true;
        if (exist_odd) cout << "first" << endl;
        else cout << "second" << endl;
    }
}


















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

using namespace std;
#define ull unsigned long long
#define si short int
#define ll long long
#define pii pair<int, int>

/*-----------------------------------------------------MATH------------------------------------------------*/
inline ll gcd(ll a, ll b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}
inline ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
inline int pwm(ll xx, ll pow, int MD) {
    if (pow < 0) { pow = pow % (MD - 1) + MD - 1; }
    ll mlt = 1;
    while (pow) {
        if (pow & 1) {
            mlt *= xx;
            mlt %= MD;
        }
        xx *= xx;
        pow >>= 1;
        xx %= MD;
    }
    return (int) mlt;
}
inline ll gcdex(ll a, ll b, ll &x, ll &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    ll xx, yy;
    ll gc = gcdex(b, a % b, yy, xx);
    x = xx;
    y = yy - (a / b) * xx;
    return gc;
}
inline int inv(ll r, int _mod) { return pwm(r % _mod, _mod - 2, _mod); }
/*-----------------------------------------------------MATH------------------------------------------------*/

const int inf = 1e9;
const int MAXN = 2e5 + 10;
ll mod = 1e9 + 7;
void solve(){
    string s;
    cin>>s;
    cout<<(char)(s[0]+1);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n=1;
    for (int i = 0; i < n; i++) solve();
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

main(){
  double data1[7]={35.5,37.5,40.0,43.0,50.0,55.0,70.0};
  double data2[7]={71.0,77.0,83.0,89.0,105.0,116.0,148.0};
  double in1, in2;
  int i, j, temp;
  int ans1, ans2;


  while(1){
    if(scanf("%lf %lf", &in1, &in2)==EOF) break;

    ans1=ans2=7;

    for(i=6;i>=0;i--){
      if(in1 < data1[i]) ans1=i;
      if(in2 < data2[i]) ans2=i;
    }

    if(ans1==ans2){
      if(ans1==0) printf("AAA\n");
      else if(ans1==1) printf("AA\n");
      else if(ans1==2) printf("A\n");
      else if(ans1==3) printf("B\n");
      else if(ans1==4) printf("C\n");
      else if(ans1==5) printf("D\n");
      else if(ans1==6) printf("E\n");
      else if(ans1==7) printf("NA\n");
    }

    if(ans1>ans2){
      if(ans1==0) printf("AAA\n");
      else if(ans1==1) printf("AA\n");
      else if(ans1==2) printf("A\n");
      else if(ans1==3) printf("B\n");
      else if(ans1==4) printf("C\n");
      else if(ans1==5) printf("D\n");
      else if(ans1==6) printf("E\n");
      else if(ans1==7) printf("NA\n");
    }

    if(ans1<ans2){
      if(ans2==0) printf("AAA\n");
      else if(ans2==1) printf("AA\n");
      else if(ans2==2) printf("A\n");
      else if(ans2==3) printf("B\n");
      else if(ans2==4) printf("C\n");
      else if(ans2==5) printf("D\n");
      else if(ans2==6) printf("E\n");
      else if(ans2==7) printf("NA\n");
    }
  }
  return 0;
}

Measured memory_bytes: 0
#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 faster ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
#define ll long long
#define ld long double
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define vi vector<int>
#define pii pair<int,int>
#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 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;
 
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;

   ll fac[n+1];
   for(int i = 1; i <= n; i++) {
      fac[i] = 1;
   }

   for(int i = 2; i <= n; i++) {
      for(int j = i; j <= n; j += i) {
         fac[j]++;
      }
   }

   ll sum = 0;
   for(int i = 1; i <= n; i++) {
      sum += i*fac[i];
   }
   cout << sum;
} 

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

   int t = 1;
   //cin >> t;
   while(t--) {
      test();
   }
   return 0;
}


Measured memory_bytes: 81776
def main() -> None:
    N, T = map(int, input().split())
    R = [[int(i) for i in input().split()] for _ in range(N)]
    ROK = [x for x in R if int(x[1]) <= T]
    if ROK:
        ROK.sort(key=lambda x: x[0])
        print(ROK[0][0])
    else:
        print('TLE')


if __name__ == '__main__':
    main()


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

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

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const int MOD = 1000000007;

const int CASES = 3;

void solve(){
    int N, K;
    cin >> N >> K;

    int ans = 0;
    vector<int> h(N);
    for(int i = 0; i <N; ++i){
        cin >> h[i];
        if(h[i] >= K) ++ans;
    }

    cout << ans << "\n";
    return;
}

int main() {
    #ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
    #else

    solve();

    #endif
    return 0;
}



Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    long long int N;
    cin >> N;
    vector<long long int> A(N);
    for(int i = 0;i < N;i++) cin >> A[i];
    long long int ans  = 0;
   for(int i = 0;i < N;i++){
     long long int t = A[i];
     for(int  j = 0;1;j++){
       if(t % 2 == 0){
         ans++;
         t = t/2;
       }else{
         break;
       }
     }
   }
   cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#ifdef tabr
#include "library/debug.cpp"
#else
#define debug(...) 0
#endif

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, 0, h) cin >> a[i];
    ll ans = 0;
    vector<vector<int>> b(h + w, vector<int>(h + w));
    rep(i, 0, h) rep(j, 0, w) {
        if (a[i][j] == '#') b[i + 1 + j][h - i + j] = 1;
    }
    vector<vector<int>> c = b;
    rep(i, 1, h + w) rep(j, 1, h + w) {
        c[i][j] += c[i][j - 1];
    }
    rep(i, 1, h + w) {
        rep(j, 1, h + w) {
            if (b[i][j] != 1) continue;
            rep(k, j + 1, h + w) {
                if (b[i][k] != 1) continue;
                int dif = k - j;
                if (i + dif < h + w) ans += c[i + dif][k] - c[i + dif][j - 1];
                if (i - dif >= 0) ans += c[i - dif][k] - c[i - dif][j - 1];
                // debug(i, j, k, ans);
            }
        }
    }
    c = b;
    rep(i, 1, h + w) rep(j, 1, h + w) {
        c[i][j] += c[i - 1][j];
    }
    rep(j, 1, h + w) {
        rep(i, 1, h + w) {
            if (b[i][j] != 1) continue;
            rep(l, i + 1, h + w) {
                if (b[l][j] != 1) continue;
                int dif = l - i;
                if (j + dif < h + w) ans += c[l - 1][j + dif] - c[i][j + dif];
                if (j - dif >= 0) ans += c[l - 1][j - dif] - c[i][j - dif];
                // debug(i, j, l, ans);
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
	LL d,g,p[11],c[11]={};
	cin>>d>>g;
	FOR(i,0,d){
		cin>>p[i]>>c[i];
	}
	LL ans=mod;
	FOR(b,0,(1<<d)){
		LL sc=0,num=0;
		FOR(i,0,d){
			if((1<<i)&b){
				sc+=c[i]+(i+1)*100*p[i];
				num+=p[i];
			}
		}
		FORD(i,d,0){
			if(sc>=g)break;
			if(((1<<i)&b))continue;
			if((i+1)*100*p[i]+sc<g){
				sc+=(i+1)*100*p[i]+c[i];
				num+=p[i];
			}else{
				num+=(g-sc+((i+1)*100-1))/((i+1)*100);
				sc+=(g-sc+((i+1)*100-1))/((i+1)*100)*((i+1)*100);
			}
		}

		if(sc>=g)ans=min(ans,num);
	}

	cout<<ans;
    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++)
typedef long long ll;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n;
  cin >> n;
  ll a[100005][3];
  rep(i, n) {
    cin >> a[i][0] >> a[i][1] >> a[i][2];
  }

  ll dp[100005][3];
  dp[0][0] = dp[0][1] = dp[0][2] = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < 3; ++j) {
      dp[i][j] = max(dp[i-1][(j+1)%3] + a[i-1][j],
                     dp[i-1][(j+2)%3] + a[i-1][j]);

    }
  }
  cout << max({dp[n][0], dp[n][1], dp[n][2]}) << endl;
  return 0;
}


Measured memory_bytes: 4992
import itertools

N, M, Q = map(int, input().split())
A = [list(map(int, input().split())) for i in range(Q)]
a_list = []
ans = 0

for i in itertools.combinations_with_replacement(range(1,M+1),N):
    ans2 = 0
    for t in A:
        if i[t[1]-1] - i[t[0]-1] == t[2]:
            ans2 += t[3]

    ans = max(ans,ans2)

print(ans)


Measured memory_bytes: 9200
open Batteries

let rec count n = if n mod 2 = 1 then 0 else 1 + count (n / 2)

let () =
  let n = Scanf.scanf "%d" (fun x -> x) in
  List.init n (fun _ -> Scanf.scanf " %d" count)
  |> List.fold_left (+) 0 |> Printf.printf "%d\n"

Measured memory_bytes: 5120
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll N;
    cin >> N;
    vector<ll> A(N), S(N+1);
    rep(i,N){
        cin >> A[i];
    }
    ll prev = -1;
    ll can1 = 0;
    ll sum = 0;
    rep(i,N){
        if(prev < 0 && sum + A[i] < 0){ 
            can1 += abs(sum + A[i]) + 1;
            sum = 1;
        }else if(prev > 0 && sum + A[i] > 0){
            can1 += sum + A[i] + 1;
            sum = -1;
        }else if(A[i] + sum == 0 && prev > 0){
            can1++;
            sum = -1;
        }else if(A[i] + sum == 0 && prev < 0){
            can1++;
            sum = 1;
        }else{
            sum += A[i];
        }
        prev = (prev==1?-1:1);
    }
    prev = 1;
    ll can2 = 0;
    sum = 0;
    rep(i,N){
        if(prev < 0 && sum + A[i] < 0){ 
            can2 += abs(sum + A[i]) + 1;
            sum = 1;
        }else if(prev > 0 && sum + A[i] > 0){
            can2 += sum + A[i] + 1;
            sum = -1;
        }else if(A[i] + sum == 0 && prev > 0){
            can2++;
            sum = -1;
        }else if(A[i] + sum == 0 && prev < 0){
            can2++;
            sum = 1;
        }else{
            sum += A[i];
        }
        prev = (prev==1?-1:1);
    }

    cout << min(can1, can2) << endl;
}


Measured memory_bytes: 4764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)


int main(){
  int n,k;
  cin >> n >> k;
  if (n%k == 0) cout << 0 << endl;
  else cout << 1 << endl;


  return 0; 
}



Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<math.h>
using namespace std;
int h[60];
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a){
		double L=0;
		double R=20;
		for(int i=0;i<60;i++)h[i]=0;
		for(int i=0;i<b;i++){
			int p,q,r;
			scanf("%d%d%d",&p,&q,&r);
			p+=30;q+=30;
			for(int j=p;j<q;j++)h[j]=max(h[j],r);
		}
	//	for(int i=0;i<60;i++)printf("%d ",h[i]);
		
		for(int i=0;i<50;i++){
			double M=(L+R)/2;
			bool ok=true;
			for(int j=30-a+1;j<30+a;j++){
				double s=M+sqrt(a*a-(j-30)*(j-30))-a;
				if((double)h[j-1]<s||(double)h[j]<s)ok=false;
			}
			if(ok)L=M;
			else R=M;
		}
		printf("%.12f\n",L);
	}
}

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

long long mod = 998244353;

int main() {
  
  long long A,B,C,D;
  cin >> A >> B >> C >> D;
  C = C-A;
  D = D-B;
  
  vector<vector<long long>> dp(C+1,vector<long long> (D+1,0));
  dp[C][D] = 1;
  
  
  long long kp;
  
  for (int i=C-1; i>=0; i--) {
    kp = 0;
    for (int j=D-1; j>=0; j--) {
      kp += dp[i+1][j+1];
      kp %= mod;
      kp *= (A+i+1);
      kp %= mod;
      dp[i][j] = kp;
      if (j==0) {
        dp[i][j] *= B;
        dp[i][j] %= mod;
      }
    }
    for (int j=D; j>=0; j--) {
      if (i==C-1 && j==D && D!=0) {
        dp[i][j] += dp[i+1][j];
        dp[i][j] %= mod;
        continue;
      }
      dp[i][j] += dp[i+1][j]*(B+j);
      dp[i][j] %= mod;
    }
  }
  
  long long ans = 0;
  
  kp = 1;
  
  for (int i=0; i<=D; i++) {
    ans += dp[0][i] * kp;
    ans %= mod;
    kp *= A;
    kp %= mod;
  }
  
  cout << ans << endl;
  
  return 0;
  
}

Measured memory_bytes: 73676
N = input()
A = [0 for _ in xrange(N)]
B = [0 for _ in xrange(N)]
for i in xrange(N):
    a, b = map(int, raw_input().split())
    A[i] = a
    B[i] = b

ans = 0
for i in xrange(N-1, -1, -1):
    a, b = A[i]+ans, B[i]
    offset = (b - (a % b)) % b
    ans += offset
print ans


Measured memory_bytes: 25580
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long LL;

int main() {
  int N; cin >> N;
  string S; cin >> S;
  int vmax = 0;
  for (int i = 1; i < N; ++i) {
    set<char> s1, s2, s;
    for (int j = 0; j < i; ++j) {
      s1.insert(S[j]);
    }
    for (int j = i; j < N; ++j) {
      s2.insert(S[j]);
    }

    for (char x : s1) if (s2.count(x)) s.insert(x);
    int cnt = s.size();
    vmax = max(vmax, cnt);
  }
  cout << vmax << endl;
}


Measured memory_bytes: 3636
#!/usr/bin/env python3
import sys
import math


def solve(N: int, X: int, m: "List[int]"):
    print(N+math.floor((X-sum(m))/min(m)))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    m = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, X, m)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
from bisect import *
N, Q = map(int, input().split())
ans = []
if N == 1:
    for q in range(Q):
        v, w = map(int, input().split())
        print(v)
else:
    c = 1
    B = [1]
    while c < 10**9:
        B.append(c+1)
        c = c*N + 1
    for q in range(Q):
        v, w = map(int, input().split())
        for i in range(bisect(B, v), bisect(B, w)):
            w = (w + (N - 2)) // N
        while v != w:
            v = (v + (N - 2)) // N
            w = (w + (N - 2)) // N
        print(v)


Measured memory_bytes: 52468
#include <cstdio>

#define i64 long long
using namespace std;
int main(){
  i64 r,n;
  while(scanf("%lld",&n),n){
    r=0LL;
    for(i64 i=1LL;i*i<n;i++){
      if(!(n%i)){
        r+=i;if(i>1)r+=n/i;
      }
    }
    // printf("%d %d\n",n,r);
    if(r>n){
      puts("abundant number");
    }
    else if(r==n&&n!=1){
      puts("perfect number");
    }
    else{
      puts("deficient number");
    }
  }
}

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

int main(void){
    string s,ts;
    int a=0,u=0;
    int n;
    int vailk= 0;
    vector<string>kc,codes;
    while(true) {
        cin >> n;
        if(n==0)break;
        kc=vector<string>(0);
        for (int i = 0; i < n; i++) {
            cin>>s;
            ts="";
            for(int j=0;j<s.length();j++){
                if(j==0)ts.push_back(s[j]);
                else if(s[j-1]=='a'||s[j-1]=='i'||s[j-1]=='u'||s[j-1]=='e'||s[j-1]=='o')ts.push_back(s[j]);
            }
            kc.push_back(ts);
        }
        for (int k = 1; k <= 50; k++) {
            vailk=k;
            codes=vector<string>(0);
            for(int i=0;i<n;i++)codes.push_back(kc[i].substr(0,min(k,(int)kc[i].length())));
            for(int i=0;i<n;i++){
                for(int j=0;j<n;j++){
                    if(i==j)continue;
                    if(codes[i]==codes[j])vailk=-1;
                }
            }
            if(vailk>0)break;
        }
        cout<<vailk<<endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1000010;
int k,n,a[MAXN],ans;
int main () {
	scanf("%d%d",&k,&n);
	for (int i=1;i<=n;i++) {scanf("%d",&a[i]);}
	sort(a+1,a+n+1);
	for (int i=2;i<=n;i++) {ans=max(ans,a[i]-a[i-1]);}
	ans=max(ans,a[1]+k-a[n]);
	printf("%d\n",k-ans); 
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
const int MAX = 5e5+100;
int nxt[27][MAX+1];
int dbl[21][MAX+1];

signed main(){
  string s;
  cin>>s;

  for(int i=0;i<=MAX;i++)
    for(int j=0;j<=26;j++) nxt[j][i]=MAX;

  int n=s.size();
  for(int i=n-1;i>=0;i--){
    chmin(nxt[s[i]-'a'][i],i+1);
    for(int j=0;j<26;j++)
      chmin(nxt[j+1][i],nxt[j][nxt[j][i]]);

    for(int j=0;j<26;j++){
      chmin(nxt[j][i],nxt[j][nxt[26][i]]);
      chmin(nxt[j+1][i],nxt[j][nxt[j][i]]);
    }
  }

  for(int i=0;i<=MAX;i++)
    dbl[0][i]=nxt[26][i];

  for(int k=0;k<20;k++)
    for(int i=0;i<=MAX;i++)
      dbl[k+1][i]=dbl[k][dbl[k][i]];

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int l,r;
    cin>>l>>r;
    l--;
    int d=20;
    while(d>=0){
      if(dbl[d][l]<=r) l=dbl[d][l];
      d--;
    }
    cout<<(l==r?"Yes":"No")<<"\n";
  }
  cout<<flush;
  return 0;
}


Measured memory_bytes: 95132
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <math.h>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int n;
  cin>>n;
  ll a[n+1][n+1]={};
  ll b[n+1][n+1]={};
  for(int i=1;i<=n;i++){
    for(int j=1;j<=n;j++){
      cin>>a[i][j];
      b[i][j]=a[i][j];
    }
  }
  ll sum=0;
  for(int k=1;k<=n;k++){
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
        b[i][j]=min(b[i][j],b[i][k]+b[k][j]);
      }
    }
  }

  for(int i=1;i<=n;i++){
    for(int j=1;j<i;j++){
      if(a[i][j]>b[i][j]){
        cout<<-1<<endl;
        return 0;
      }
      bool flag=0;
      for(int k=1;k<=n;k++){
        if(i==k||j==k) continue;
        if(b[i][j]==(b[i][k]+b[k][j])) flag=1;

      }
      if(!flag) sum+=a[i][j];
    }
  }
  cout<<sum<<endl;
  return 0;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


inline li calc(li x, li y) {
    return x + y - 1;
}

int main() {
    li a, b, c, d;
    cin >> a >> b >> c >> d;
    li x = abs(c - a);
    li y = abs(d - b);
    if (__gcd(x, y) == 1) {
        cout << calc(x, y) << endl;
    } else {
        li g = __gcd(x, y);
        cout << calc(x / g, y / g)*g << endl;
    }

    return 0;
}

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

#define int long long

const int N = 1e5 + 10;
int n, mark[2][N], cnt[2][N];
vector <int> adj[2][N];

void dfs(int x, int y, int c) {
	mark[x][y] = c;
	cnt[x][c]++;
	for (int u : adj[x][y])
		if (!mark[x ^ 1][u])
			dfs(x ^ 1, u, c);
}

int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--; y--;
		adj[0][x].push_back(y);
		adj[1][y].push_back(x);
	}
	
	for (int i = 0, x = 1; i < N; i++)
		if (!mark[0][i])
			dfs(0, i, x++);
	
	int ans = -n;
	for (int i = 0; i < N; i++)
		ans += cnt[0][i] * cnt[1][i];
	cout << ans << endl;
}

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

int main(){
	int n; cin >> n;
    vector<int> a(n), b(n), c(n-1);
    for(int i=0; i<n; i++) cin >> a[i];
    for(int i=0; i<n; i++) cin >> b[i];
    for(int i=0; i<n-1; i++) cin >> c[i];

    int ans=accumulate(b.begin(),b.end(),0);
	for(int i=0; i<n-1; i++){
        if(a[i]<=n-1 && a[i]+1==a[i+1]) ans += c[a[i]-1];
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];
 
int n,m,num=0;
int i,j;
ll ans=0;
ll cost[100005];
ll mini[100005];
bool visited[100005];
int renketu = 0;
ll kiroku[100005];
int kazu=0;

void dfs(int x){
	if(visited[x])return;
	else{
		visited[x]=true;
		if(cost[x]<mini[num]){
			kiroku[kazu] = mini[num];
			mini[num] = cost[x];
			kazu += 1;
		}else{
			kiroku[kazu] = cost[x];
			kazu += 1;
		}
		for(int i=0;i<G[x].size();i++){
			dfs(G[x][i]);
		}
	}
}


int main(){
	cin>>n>>m;
	fill(mini,mini+n,INF);
	fill(kiroku,kiroku+n,INF);
	for(i=0;i<n;i++){
		cin>>cost[i];
	}
	for(i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	for(i=0;i<n;i++){
		if(!visited[i]){
			dfs(i);
			renketu+=1;
			num += 1;
		}
	}
	if(renketu*2-2>n){
		cout<<"Impossible"<<endl;
	}else if(renketu==1){
		cout<<0<<endl;
	}else{
		for(i=0;i<renketu;i++){
			ans += mini[i];
		}
		int nokori = renketu-2;
		sort(kiroku,kiroku+n);
		if(nokori>=1){
			for(i=0;i<nokori;i++){
				ans += kiroku[i];
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 8192
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define MOD 1000000007

int main() {
  string s, t;
  cin >> s >> t;
  int n = s.size();
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    ans += (s[i] != t[i]);
  }
  cout << ans << endl;
  return 0;
}

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

int f(const void *a,const void *b){
  return *(int*)a-*(int*)b;
}

int main(){
  int N,d[200000];
  scanf("%d",&N);
  for(int i=0;i<N;i++)
    scanf("%d",d+i);
  qsort(d,N,sizeof(int),f);
  printf("%d\n",d[N/2]-d[N/2-1]);
  return 0;
}

Measured memory_bytes: 2284
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <queue>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  int N;
  std::cin >> N;
  std::vector<int> A(N), B(N);
  for (int &x: A) {
    std::cin >> x;
  }
  for (int &x: B) {
    std::cin >> x;
  }
  for (int i: range(0, N)) {
    if (A[i] > B[i]) {
      std::cout << "-1\n";
      return 0;
    }
  }
  auto at = [&](int i) {
    if (i < 0) i += N;
    if (i >= N) i -= N;
    return i;
  };
  auto check = [&](int i) {
    return B[at(i - 1)] < B[i] && B[i] > B[at(i + 1)];
  };
  long long ans = 0;
  std::queue<int> que;
  for (int i: range(0, N)) {
    if (check(i)) {
      que.push(i);
    }
  }
  while (!que.empty()) {
    int i = que.front();
    que.pop();
    int border = std::max({ B[at(i - 1)], A[i], B[at(i + 1)]});
    int sum = B[at(i - 1)] + B[at(i + 1)];
    int cnt = (B[i] - border) / sum;
    ans += cnt;
    B[at(i)] -= cnt * sum;
    if (B[i] - sum >= A[i]) {
      ++ans;
      B[i] -= sum;
      if (check(at(i - 1))) que.push(at(i - 1));
      if (check(at(i + 1))) que.push(at(i + 1));
    }
  }
  for (int i: range(0, N)) {
    if (A[i] != B[i]) {
      std::cout << "-1\n";
      return 0;
    }
  }
  std::cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 2176