akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
 
int dig(int x)
{
    int ans=0;
    while(x>0)
    {
        ans++;
        x/=10;
    }
    return ans;
}
int minimumChar(string S1, string S2) 
{ 
    // Get the sizes of both strings 
    int n = S1.size(), m = S2.size(); 
  
    int ans = INT_MAX; 
  
    // Traverse the string S2 
    for (int i = 0; i < m - n + 1; i++) { 
        int minRemovedChar = 0; 
  
        // From every index in S2, check the number of 
        // mis-matching characters in substring of 
        // length of S1 
        for (int j = 0; j < n; j++) { 
            if (S1[j] != S2[i + j]) { 
                minRemovedChar++; 
            } 
        } 
  
        // Take minimum of prev and current mis-match 
        ans = min(minRemovedChar, ans); 
    } 
  
    // return answer 
    return ans; 
} 
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    string s,t;
    cin>>s>>t;
    cout << minimumChar(t,s);
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int n,k,a;
long long b,ans;
map<int,vector<int>> m;
int main(){
	scanf("%d%d", &n, &k);
	m[0].push_back(0);
	rep(i,n){
		scanf("%d", &a);
		b=(b+a-1)%k;
		ans += m[b].end() - upper_bound(m[b].begin(), m[b].end(),i+1-k);
		m[b].push_back(i+1);
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 22144
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a; i < n; i++)
#define per(i,n,a) for (int i = n - 1; i >= a; i--)
using namespace std;

long long x, y, ans, i;
int main() {
    cin >> x >> y;
    for (i = x; i <= y; i *= 2) ans++;
    cout << ans << endl;
}


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

using namespace std;

int main(){
    
    int a,b;
    cin >> a >> b;
    
    cout << a/b << " " << a%b << " " << setprecision(6) << flush;
    cout << fixed << setprecision(6) << double(a)/b << endl;
    
    return 0;
    
}


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

int a[300];

int main(){
    int n,ans=0;
    cin>>n;
    for(int i=0;i<n;i++){
        char ch;
        cin>>ch;
        if(!a[ch]){
            a[ch]=1;
            ans++;
        }
    }
    if(ans==3)
        cout<<"Three"<<endl;
    else
        cout<<"Four"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include <cmath>
#include <limits>
#include<set>
#include <iomanip>
#include <queue>
#pragma GCC optimize("Ofast")
using namespace std;
const long long INF=20000000000;
//setprecision(2) <<
typedef struct {
	int h;
	int w;
}Point;

long nCr(int n, int r) {
    long ans = 1;
    for (int i = n; i > n - r; --i) {
        ans = ans*i;
    }
    for (int i = 1 ; i < r + 1; ++i) {
        ans = ans / i;
    }
    return ans;
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin>>n;
	string s[n];
	vector<string>v;
	for(int i=0;i<n;i++){
		cin>>s[i];
		sort(s[i].begin(),s[i].end());
		v.push_back(s[i]);
	}
	sort(v.begin(),v.end());
	
	
	for(int i=0;i<n;i++){
		//cout<<v[i]<<endl;
	}
	v.push_back("");
	long long ans=0;
	int d=1;
	for(int i=0;i<n;i++){

		if(v[i]==v[i+1]){
			d++;
		}else{
			if(d>=2)ans+=nCr(d, 2);
			d=1;
		}
	}
	
	if(d>=2)ans+=nCr(d, 2);
	
	cout<<ans<<endl;
	
}
	


Measured memory_bytes: 11252
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
d = [IL() for i in range(N)]

cnt = 0
for i,j in d:
  if i == j:
    cnt += 1
  else:
    cnt = 0
  if cnt == 3:
    print("Yes")
    exit()
else:
  print("No")

Measured memory_bytes: 9228
#include<bits/stdc++.h>
using namespace std;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int h, w;
	cin >> h >> w;
	string s[h];
	for (int i = 0; i < h; ++i) cin >> s[i];
	int dp[h][w];
	fill (dp[0], dp[0] + h * w, 0x7fffffff);
	dp[0][0] = (s[0][0] == '#');
	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			if (i) dp[i][j] = min(dp[i][j], dp[i - 1][j] + (s[i][j] == '#' && s[i - 1][j] == '.'));
			if (j) dp[i][j] = min(dp[i][j], dp[i][j - 1] + (s[i][j] == '#' && s[i][j - 1] == '.'));
		}
	}
	cout << dp[h - 1][w - 1];
}

Measured memory_bytes: 256
from fractions import gcd
#from math import gcd
def lcm(a,b):
    return a*b//gcd(a,b)
def main():
    n=int(input())
    T=set(list(int(input()) for _ in  range(n)))
    ans=1
    for t in T:
        ans = lcm(t,ans)
    print(ans)
main()

Measured memory_bytes: 5112
#include<stdio.h>
        int main(){
          int N,A,B;
          if(1<=N<=20,1<=A<=50,1<=B<=50){
          scanf("%d %d %d",&N,&A,&B);
          int Train=N*A;
          if(Train < B){
            printf("%d",Train);
          }else{
            printf("%d",B);
          }
          return 0;
        }
        }

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

int64_t MOD = 1000000007;
int64_t MAX = 9223372036854775807;
double PI = 3.141592653589793;

int main()
{
    string S;
    cin >> S;
    for (int i = 0; i < 3; i++)
    {
        if (S[i] == '1')
            cout << '9';
        else if (S[i] == '9')
            cout << '1';
        else
            cout << S[i];
    }
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/panasonic2020/submissions/10887966

a = input()
b = input()
c = input()

# maxtestcase
#a = 'a' * 2000
#b = 'a' * 2000
#c = 'a' * 2000

La = len(a)
Lb = len(b)
Lc = len(c)

def func(a, b):
    ret = set()
    for i in range(-len(b)+1, len(a)):
        ok = True
        for j in range(max(0, i), min(len(a), len(b)+i)):
            if a[j] != '?' and b[j-i] != '?' and a[j] != b[j-i]:
                ok = False
                break
        if ok:
            ret.add(i)
    return ret

L1 = func(a, b)
L2 = func(a, c)
L3 = func(b, c)
L1.add(-Lb)
L1.add(La)
L2.add(-Lc)
L2.add(La)
L3.add(-Lc)
L3.add(Lb)
ans = 10000
for i in L1:
    for j in L2:
        if j - i in L3 or j - i <= -Lc or j - i >= Lb:
            lo = min(0, i, j)
            hi = max(len(a), i+len(b), j+len(c))
            ans = min(ans, hi-lo)
    for k in L3:
        j = i + k
        if j >= La or j <= -Lc:
            lo = min(0, i, j)
            hi = max(len(a), i+len(b), j+len(c))
            ans = min(ans, hi-lo)
for j in L2:
    for k in L3:
        i = j - k
        if i >= La or i <= -Lb:
            lo = min(0, i, j)
            hi = max(len(a), i+len(b), j+len(c))
            ans = min(ans, hi-lo)
    
print(ans)


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

lint a, b, n;

lint f(lint x) {
    return a * x / b - a * (x / b);
}

int main() {
    cin >> a >> b >> n;
    cout << f(min(n, b - 1)) << endl;
}

Measured memory_bytes: 3596
/*************************************************************************
  > File Name: b.cpp
  > Author: Samuel
  > Mail: enminghuang21119@gmail.com
  > Created Time: Sun Mar 22 20:03:30 2020
*************************************************************************/

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

bool check(string &s, int start, int end) {
    bool ans = 1;
    for (int i = 0; start + i < end - i; i++) {
        ans &= s[i + start] == s[end - i];
    }
    return ans;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    int n = s.length();
    cout << ((check(s, 0, n - 1) && check(s, 0, (n - 1) / 2 - 1) && check(s, (n + 3) / 2 - 1, n - 1)) ? "Yes" : "No")<< '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int,int);
int lcm(int,int);

int main(){
	int x,y;
	while(scanf("%d %d",&x,&y)>0){
		printf("%d %d\n",gcd(x,y),lcm(x,y));
	}
	
	return 0;
}

int gcd(int x,int y){
	if(y==0)return x;
	if(x==0)return y;
	if(x>y)return gcd(y,x%y);
	else return gcd(x,y%x);
}
int lcm(int x,int y){
	return x/gcd(x,y)*y;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
    using namespace std;
    
    typedef long long ll;
    typedef pair<ll , ll> pair_t;
    
    bool comp(const pair_t &a, const pair_t &b) {
        return a.first < b.first;
    }
    
    int main(){
        ll n , t , x ,y ;
        cin >> n ;
        vector<int> v1(n) , v2(n);
        for(ll i = 0 ; i < n ; i++){
            cin >> v1[i];
        }
        for(ll i = 0 ; i < n ; i++){
            cin >> v2[i];
        }
        for(ll i = 1 ; i < n ; i++){
            v1[i] += v1[i-1];
        }
        for(ll i = n - 2 ; i >= 0 ; i--){
            v2[i] += v2[i+1];
        }
        ll temp;
        ll ans = 0;
        for(ll i = 0 ; i < n ; i++){
            temp = v1[i] + v2[i];
            ans = max(ans, temp);
        }
        
        cout << ans << endl;
        
        return 0;
        
    }

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

const int MOD = 1000000000 + 7;

long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  while (n > 0) {
    // 最下位bitが立っていたら x^{2^i}を掛ける
    if (n & 1) {
      res = res * x % mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}

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

  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    mp[a]++;
  }

  vector<pair<int, int>> v;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    int val = it->first;
    int cnt = it->second;
    v.push_back(make_pair(val, cnt));
  }

  if (n & 1) {
    bool is_ok = true;
    if (v[0].first != 0 || v[0].second != 1 || v.size() != (n + 1) / 2) {
      is_ok = false;
    }
    for (int i = 1; i < v.size(); i++) {
      if (v[i].second != 2) {
        is_ok = false;
      }
    }
    if (is_ok) {
      cout << mod_pow(2, v.size() - 1, MOD) << endl;
    } else {
      cout << 0 << endl;
    }
  } else {
    bool is_ok = true;
    if (v.size() != n / 2) {
      is_ok = false;
    }
    for (int i = 0; i < v.size(); i++) {
      if (v[i].second != 2) {
        is_ok = false;
      }
    }
    if (is_ok) {
      cout << mod_pow(2, v.size(), MOD) << endl;
    } else {
      cout << 0 << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 3840
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

bool is_prime(int x) {
	if (x <= 1) return false;
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0) return false;
	}
	return true;
}

map<string, int> memo;

using P=pair<int, int>;

struct Clock {
	int hour, minute, second;
	void set(int h, int m, int s) {
		hour = h; minute = m; second = s;
	}
	string to_str() {
		string h, m, s;
		h = to_string(hour);
		m= to_string(minute);
		s= to_string(second);
		if (h.size() < 2) h = "0" + h;
		if (m.size() < 2) m = "0" + m;
		if (s.size() < 2) s = "0" + s;
		return h + ":" + m + ":" + s;
	}
	void shift(int diff_second) {
		int h, m;
		h = diff_second / 3600;
		m = diff_second / 60;
		diff_second %= 60;
		second += diff_second;
		
	}
};
int main() {
	//sort(a.begin(),a.end());
	int n;
	cin >> n;
	vector<double> a(n);
	rep(i, n) cin >> a[i];
	sort(a.begin(),a.end());
	double c = (a[0]+a[1])/2;
	for (int i = 2; i < n; i++) {
		c = (c + a[i]) / 2;
	}
	cout << c;
	return 0;
}









Measured memory_bytes: 256
N,K = map(int, input().split())
List = list(map(int, input().split()))

a=[]

for i in range(N):
    a.append(-1)
#print(a)
b=1
for i in range(N):
    if a[b-1]==-1:
        a[b-1]=i+1
        b=List[b-1]
        
    else:
        c=i
        break
#print(a)
#print(b,c)

num=a[b-1]-1
T=c-num
#print(T)
e=1
if K<num:
    for i in range(K):
        e=List[e-1]
    print(e)
else:
    qw=(K-num)%T
    List_new=[]
    for i in range(T):
        List_new.append(b)
        b=List[b-1]
    print(List_new[qw])

Measured memory_bytes: 32240
N = int(input())
answer = [0] * (10001)

for x in range(1, 100):
    for y in range(1, 100):
        for z in range(1, 100):
            index = x * x + y * y + z * z + x * y + y * z + z * x - 1
            if index > N:
                break
            answer[index] += 1
            

for i in range(N):
    print(answer[i])

Measured memory_bytes: 9140
import java.util.*;

public class Main
{
    public static void main( String[] args )
    {
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int N = sc.nextInt();
        int arr = 0;
        for(int i = 0;i<N;i++)arr+=sc.nextInt();
        if(H <= arr){
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 47604
#include<iostream>
#include<string.h>
#define MAX_NUMBER 100005

struct P{
    char name[100];
    int t;
};

P Q[MAX_NUMBER];
int head = 0;
int tail = 0;

void enqueue(char s[],int x){
    
    strcpy(Q[tail].name,s);
    Q[tail++].t = x;
    
    if(tail==MAX_NUMBER){
        tail = 0;
        //std::cout << "tailを更新\n";
    }
}

int dequence(){
    
    int num=head++;
    //std::cout << Q[num].name << ' ' << Q[num].t << '\n';
    
    if(head==MAX_NUMBER){
        head = 0;
        //std::cout << "headを更新\n";
    }
    return Q[num].t;
}

int main(){

    int n,q,t;
    int elaps = 0;
    char s[100];
    //int count[5],j=0;
    std::cin >> n >> q;
    
    for(int i=0;i<n;i++){
        std::cin >> s;
        std::cin >> t;
        enqueue(s,t);
        /*if(t>3){
            count[j++] = t;
        }*/
    }
    
    /*for(int i=0;i<5;i++){ std::cout << count[i] << ' ';}
    std::cout << '\n';*/
    
    while(head!=tail){
        int c = head;
        int tmp = dequence();
        //std::cout << head << ' ' << tail << '\n';
        if(tmp > q ){
            enqueue( Q[c].name ,tmp-q);
            elaps += q;
        }else{
            elaps += tmp;
            std::cout << Q[c].name << ' ' << elaps <<  '\n';
        }
    }
    return 0;
}



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

int main ()
{
  string str;
  getline(cin, str);
  
  for (int i = 0; i <= str.size(); i++){
    if (str[i] <= 'z' && str[i] >= 'a'){
      str[i] += 'A' - 'a';
    }
  }
  cout << str << endl;

  return 0;
}

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

#define ll long long int 

ll ans;
ll mod=1e9+7;
ll h,w;
char arr[1005][1005];
ll grid[1005][1005];

int isvalid(ll x,ll y)
{
    if(x>=0 && y>=0 && x<h && y<w)
    {
        if(arr[x][y]=='.')
        {
            return 1;
        }
    }
    return 0;
}

void rec(ll i , ll j)
{
    if(i==(h-1) && j==(w-1))
    {
        ans = ans + 1;
        ans%=mod;
    }

    if(isvalid(i+1,j))
    {
        rec(i+1,j);
    }
    if(isvalid(i,j+1))
    {
        rec(i,j+1);
    }
    return ;
}

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

    cin >> h >> w;
    ll i,j;
    for(i=0;i<h;i++)
    {
        for(j=0;j<w;j++)
        {
            cin >> arr[i][j];
        }
    }
     for (int i=0; i<h; i++) 
    { 
        if (arr[i][0] == '.') 
            grid[i][0] = 1; 
  
        // If we encounter a blocked cell in leftmost 
        // row, there is no way of visiting any cell 
        // directly below it. 
        else
            break; 
    } 
  
    // Similarly initialize the topmost row 
    for (int i=0; i<w; i++) 
    { 
        if (arr[0][i] == '.') 
            grid[0][i] = 1; 
  
        // If we encounter a blocked cell in bottommost 
        // row, there is no way of visiting any cell 
        // directly below it. 
        else
            break; 
    } 

    for(i=1;i<h;i++)
    {
        for(j=1;j<w;j++)
        {
            if(arr[i][j]=='#') continue;

            if(grid[i-1][j]>0)
            {
                grid[i][j] = ((grid[i][j])%mod + (grid[i-1][j])%mod)%mod;
            }

            if(grid[i][j-1]>0)
            {
                grid[i][j] = ((grid[i][j])%mod + (grid[i][j-1])%mod)%mod;
            }

        }
    }

    //rec(0,0);

    cout << grid[h-1][w-1] << '\n';
}

Measured memory_bytes: 9088
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<math.h>
#include<algorithm>
#include<iomanip>
#include<deque>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;

#define vvint(vec,n,m,l) vector<vector<int>> vec(n,vector<int>(m,l));
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>;
#define pint pair<int,int>;
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")
#define ret return 0

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

	ll n;
	cin >> n;
	ll tmp = n;
	int keta = 0;
	int sum = 0;
	while (n!=0)
	{
		sum += n % 10;
		n /= 10;
		keta++;
		
	}
	if (tmp%sum == 0)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	ret;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int a = sc.nextInt();
      int b = sc.nextInt();
      int p = a+b;
      int q = a*b;
      int r = a-b;
      int pq = Math.max(p,q);
      int pqr = Math.max(pq,r);
      System.out.println(pqr);
      sc.close();
    }
}

Measured memory_bytes: 23508
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    int a[100010];
    rep(i, n) cin >> a[i];
    int ans = INF2;
    rep(k, 2) {
        int sum[100010] = {};
        int tmp = 0;
        rep(i, n) {
            sum[i + 1] = sum[i] + a[i];
            bool isplus = (i + k) % 2;
            if(isplus && sum[i + 1] <= 0) {
                tmp += 1 - sum[i + 1];
                sum[i + 1] = 1;
            } else if (!isplus && sum[i + 1] >= 0) {
                tmp += sum[i + 1] + 1;
                sum[i + 1] = -1;
            }
        }
        ans = min(ans, tmp);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
public class Main {
    public String getGreeting() {
        return "Hello world.";
    }

    public static boolean is_even(int a){
        if(a % 2 == 0){
            return true;
        }else{
            return false;
        }
    }
    public static void main(String[] args) {
        // System.out.println(new App().getGreeting());
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if(is_even(a) || is_even(b)){
            System.out.println("Even");
        }else{
            System.out.println("Odd");
        }
    }
}


Measured memory_bytes: 21332
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

import static java.lang.Integer.parseInt;

/**
 * Decimal Sequences - Accepted
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		int n = parseInt(br.readLine());
		char[] seq = new char[n];

		int _i = 0;
		while ((line = br.readLine()) != null && !line.isEmpty()) {
			for (int i = 0; i < line.length(); i += 2, _i++) {
				seq[_i] = line.charAt(i);
			}
		}

		//solve
		boolean[] nums = new boolean[1_000_000];
		outer:
		for (int i = 0; i < n; i++) {
			for (int j = i; j < n; j++) {
				int len = j - i + 1;
				if ((seq[i] == '0' && len > 1) || len > 4) continue outer;
				//
				char[] _seq = Arrays.copyOfRange(seq, i, j + 1);
				nums[parseInt(String.valueOf(_seq))] = true;
			}
		}

		for (int i = 0; i < nums.length; i++) {
			if (!nums[i]) {
				System.out.println(i);
				break;
			}
		}

	} //end main
}

Measured memory_bytes: 26380
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 1;i<n;i++)
int main(){
double a, b, x;
cin >>a>>b>>x;

cout << fixed << setprecision(10);
if(a*a*b<=2.0*x){
cout << atan(2.0*(b-x/(a*a))/a)/(2*M_PI)*360<<endl;
}else{cout << atan(a*b*b/2.0/x)/(2*M_PI)*360<<endl;
}
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
            int N = Integer.parseInt(reader.readLine());
            String S = reader.readLine();

            int count = 0;
            char c = ' ';
            for (int i = 0; i < N; i++) {
                char c2 = S.charAt(i);

                if (c != c2) {
                    c = c2;
                    count++;
                }
            }

            System.out.println(count);
        }
    }

}


Measured memory_bytes: 23252
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vector<vector<int> > g(N);
	int x, y;
	vector<int> cnt(N);
	for (int i = 0; i < M; i++) {
		cin >> x >> y; x--; y--;
		g[x].push_back(y);
		cnt[y]++;
	}
	queue<int> qu;
	int INF = (int)1 << 60;
	vector<int> dp(N, -INF);
	for (int i = 0; i < N; i++) {
		if (cnt[i] == 0) {
			qu.push(i);
			dp[i] = 0;
		}
	}
	int res = 0;
	while (qu.size()) {
		int a = qu.front(); qu.pop();
		for (int i : g[a]) {
			dp[i] = max(dp[i], dp[a] + 1);
			res = max(res, dp[i]);
			cnt[i]--;
			if (cnt[i] == 0) {
				qu.push(i);
			}
		}
	}

	cout << res << endl;
}

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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;


int main(){
	int ax, ay, bx, by;
	cin >> ax >> ay >> bx >> by;
	int dx = bx - ax, dy = by - ay;
	cout << string(dx, 'R') << string(dy, 'U') <<
		string(dx, 'L') << string(dy, 'D') <<
		"D" << string(dx+1, 'R') << string(dy+1, 'U') << "L" <<
		"U" << string(dx+1, 'L') << string(dy+1, 'D') << "R" << endl;

	return 0;
}

Measured memory_bytes: 256
import copy
n, k = [int(i) for i in input().split()]

h_arr = []
for i in range(n): 
    h_arr.append(int(input()))

h_arr = sorted(h_arr)
r = 10**10
for i in range(n-k+1):
    r = min(r,h_arr[i+k-1]-h_arr[i])

print(r)

Measured memory_bytes: 8660
import math

N, D = map(int, input().split())
x = [list(map(int, input().split())) for i in range(N)]

kazu = 0

for i in range(N):
    if math.sqrt(x[i][0]**2 + x[i][1]**2) <= D:
        kazu += 1

print(kazu)

Measured memory_bytes: 45380
#include <map>
#include <set>
#include <list>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <bitset>
#include <vector>
#include <cstdio>
#include <string>
#include <cstring>
#include <sstream>
#include <iomanip>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
using namespace std;
vector<int> a[100005];
bool v[100005],c[100005];
int n,m,s0,s1;
void dfs (int x,bool f) {
	int i;
	v[x]=true;
	c[x]=f;
	if (!f) s0++; else s1++;
	for (i=0;i<(int)a[x].size();i++) {
		if (!v[a[x][i]]) dfs(a[x][i],!f);
		else  {
			if (c[a[x][i]]==f) {
				printf("%lld\n",(long long)n*(long long)(n-1)/2-m);
				exit(0);
			}
		}
	}
}
int main ( ) {
	int i;
	scanf("%d%d",&n,&m);
	for (i=1;i<=m;i++) {
		int x,y;
		scanf("%d%d",&x,&y);
		a[x].push_back(y);
		a[y].push_back(x);
	}
	dfs(1,true);
	printf("%lld\n",(long long)s0*(long long)s1-m);
	return 0;
}

Measured memory_bytes: 6400
def resolve():
    import collections
    n, m = map(int, input().split())
    hw = [[0] for _ in range(n+1)]
    for i in range(m):
        a, b = map(int, input().split())
        hw[a].append(b)
        hw[b].append(a)

    dis = [0] * (n+1)
    arr = [-1] * (n+1)
    que = collections.deque([1])
    while len(que) != 0:
        a = que.popleft()
        test = hw[a]
        for i in range(len(test)):
            if test[i] != 0:
                goal = test[i]
                if arr[goal] == -1:
                    arr[goal] = a
                    que.append(goal)
    if 0 in arr[2:]:
        print("No")
    else:
        print("Yes")
        for i in range(2, len(arr)):
            print(arr[i])
resolve()

Measured memory_bytes: 37616
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;

int main(){
    int N;
    cin >> N;
    int ans = 0;
    if(N%2 == 0){
    ans = N / 2;
    }
    else{
        ans = N / 2 + 1;
    }
    cout << ans << endl;
}

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

//短縮
#define rep(i,n) for(int i=0;i<(n);++i)
//sort()用
#define all(v) v.begin(), v.end()

#define PB(N) push_back(N)

using namespace std;

using Graph = vector<vector<int>>;

int main(){
  long double A;
  long double B;
  cin >> A >> B;

  long long buffer=floorl(A*B);cout << buffer;
  return 0;
}


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

int main()
{
	int n;
	int count = 0;
	vector<int> vec;
	
	cin >> n;

	for (int i = 0; i < n; i++)
	{
		int tmp;
		cin >> tmp;

		vec.push_back(tmp);
	}

	for (auto ite = vec.begin(); ite != vec.end(); ite++)
	{
		int tmp = *ite;

		while (tmp % 2 == 0)
		{
			++count;
			tmp /= 2;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 384
using System;
using System.IO;
 
class Program
{
    static void Solve()
    {
        var A = sc.Int();
        var B = sc.Int();
        var C = sc.Int();
        var X = sc.Int();

        var cnt = 0;

        for (var i = 0; i <= A; i++)
            for (var j = 0; j <= B; j++)
                for (var k = 0; k <= C; k++)
                    if (500 * i + 100 * j + 50 * k == X)
                        cnt++;
        
        pr.WriteLine(cnt);
    }
 
 
    static void Main(string[] args)
    {
        // pr.AutoFlush = true;
        Solve();
        pr.Flush();
    }
 
    static Scanner sc = new Scanner();
    static Printer pr = new Printer();
}
 
#region IO
class Scanner
{
    private int _i = 0; 
    private string[] line = new string[0];
 
    private T[] Enumerate<T>(int n, Func<T> f)
    {
        T[] ret = new T[n];
        for (int i = 0; i < n; i++)
            ret[i] = f();
        return ret;
    }
 
    public string Str()
    {
        if (line.Length <= _i)
        {
            line = Console.ReadLine().Split(' ');
            _i = 0;
        }
 
        return line[_i++];
    }
 
    public int Int() => int.Parse(Str());
    public long Long() => long.Parse(Str());
    public double Double() => double.Parse(Str());
    public int[] Int(int n) => Enumerate(n, Int);
    public long[] Long(int n) => Enumerate(n, Long);
    public double[] Double(int n) => Enumerate(n, Double);
    public string[] Str(int n) => Enumerate(n, Str);
}
 
class Printer : StreamWriter
{
    public Printer() : base(Console.OpenStandardOutput())
    {
        AutoFlush = false;
    }
}
#endregion

Measured memory_bytes: 13140
PROGRAM ATCODER

implicit none
integer :: a(5),i,dp=10,index=6,ans=0

do i = 1, 5
  read*, a(i)
  call chmin(dp,mod(a(i),10),index,i)
end do

do i = 1, 5
  if ( i == index .or. mod(a(i),10) == 0 ) cycle
  if ( a(i) < 10 ) then
    a(i) = 10
    cycle
  end if
  a(i) = (a(i)/10)*10 + 10
end do

do i = 1, 5, 1
  ans = ans + a(i)
end do

print'(i0)', ans 

contains
  subroutine chmin(dp,x,index,i)
  implicit none
  integer :: dp,x,index,i

  if (dp > x .and. x /= 0) then
  	dp = x
    index = i
  	return
  end if
  
  end subroutine

END PROGRAM ATCODER

Measured memory_bytes: 768
#[allow(dead_code)]
fn main() {
    let n = i::u();
    let mut a = 0;
    let mut l = n;
    for _ in 0..10 {
        a += l % 10;
        l /= 10;
    }
    println!("{}", if n % a == 0 { "Yes" } else { "No" });
}

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::num::*;
#[allow(unused_imports)]
use std::str::*;

#[allow(dead_code)]
mod i {
    use super::*;

    pub fn read<T: FromStr>() -> T {
        stdin()
            .bytes()
            .map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse::<T>()
            .ok()
            .unwrap()
    }

    pub fn str() -> String {
        read()
    }

    pub fn s() -> Vec<char> {
        str().chars().collect()
    }

    pub fn i() -> i64 {
        read()
    }

    pub fn u() -> usize {
        read()
    }

    pub fn u2() -> (usize, usize) {
        (read(), read())
    }

    pub fn u3() -> (usize, usize, usize) {
        (read(), read(), read())
    }

    pub fn f() -> f64 {
        read()
    }

    pub fn c() -> char {
        read::<String>().pop().unwrap()
    }

    pub fn iv(n: usize) -> Vec<i64> {
        (0..n).map(|_| i()).collect()
    }

    pub fn iv2(n: usize) -> Vec<(i64, i64)> {
        (0..n).map(|_| iv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv(n: usize) -> Vec<usize> {
        (0..n).map(|_| u()).collect()
    }

    pub fn uv2(n: usize) -> Vec<(usize, usize)> {
        (0..n).map(|_| uv(2)).map(|a| (a[0], a[1])).collect()
    }

    pub fn uv3(n: usize) -> Vec<(usize, usize, usize)> {
        (0..n).map(|_| uv(3)).map(|a| (a[0], a[1], a[2])).collect()
    }

    pub fn fv(n: usize) -> Vec<f64> {
        (0..n).map(|_| f()).collect()
    }

    pub fn cmap(h: usize) -> Vec<Vec<char>> {
        (0..h).map(|_| s()).collect()
    }
}


Measured memory_bytes: 4352
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N, M;
vector<tuple<int, int, int>> v;
int cost[100][100];

signed main(){
	cin >> N >> M;
	rep(i, N){
		rep(j, N){
			cost[i][j] = 1e9L;
		}
	}
	rep(i, N){
		cost[i][i] = 0;
	}

	rep(i, M){
		int a, b, c;
		cin >> a >> b >> c;
		a--; b--;
		v.pb({ c,a,b });
		cost[a][b] = c;
		cost[b][a] = c;
	}
	rep(i, N){
		rep(j, N){
			rep(k, N){
				cost[j][k] = min(cost[j][k], cost[j][i]+cost[i][k]);
			}
		}
	}
	sort(all(v));

	int ans = 0;
	rep(i, v.size()){
		int a = get<1>(v[i]);
		int b = get<2>(v[i]);
		int c = get<0>(v[i]);
		if(cost[a][b] != c) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  ll n ,x;
  cin >> n >> x;
  vl a(n);
  rep(i,n)cin>>a[i];

  ll ans = 0;
  srep(i,1,n){
    ll sum = a[i]+a[i-1];
    ll diff = sum - x;
    //show(diff);
    if(diff <= 0LL)continue;    
    ans+=diff;
    ll tmp = a[i]-diff;
    if(tmp<0LL) a[i-1]+=tmp;
    a[i] = max(0LL,tmp);
    //show(a[i]);
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1024
N=int(input())
A=list(map(int,input().split()))

cnt4=0
cnt2=0
odd=0
for i in A:
    if i%4==0:
        cnt4+=1
    elif i%2==0:
        cnt2+=1
    else:
        odd+=1   

if cnt2==0:
    if odd<=cnt4+1:print("Yes")
    else:print("No")
else:
    if odd<=cnt4:print("Yes")
    else:print("No")


Measured memory_bytes: 15020
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<tuple<double,double,double>> circles;
    rep(i,2){
        double tx,ty;cin>>tx>>ty;
        circles.push_back(make_tuple(tx,ty,0));
    }
    double n;cin>>n;
    rep(i,n){
        double tx,ty,tr;cin>>tx>>ty>>tr;
        circles.push_back(make_tuple(tx,ty,tr));
    }
    function<double(double,double,double,double)> distance = [=](double ax, double ay, double bx, double by){
        return sqrt(pow(ax-bx,2)+pow(ay-by,2));
    };
    vector<vector<double>> mat(n+2,vector<double>(n+2,0));
    rep(i,n+2){
        rep(j,n+2){
            double dist = max(0.0,(get<2>(circles[i])+get<2>(circles[j]))*(-1.0)+
            distance(get<0>(circles[i]), get<1>(circles[i]),
            get<0>(circles[j]), get<1>(circles[j])));
            mat[i][j] = mat[j][i] = dist;
        }
    }
    DEBUG{
        rep(i,n+2){
            rep(j,n+2){
                cout << mat[i][j] << " ";
            }
            cout << endl;
        }
    }
    priority_queue<pair<double,double>, vector<pair<double,double>>,greater<pair<double,double>>> pq;
    vector<double> d(n+2,1e+14);
    vector<bool> check(n+2,false);
    pq.push(make_pair(0,0));
    d[0]=0;
    while(!pq.empty()){
        auto now = pq.top();
        DEBUG{
            cout << "now: " << now.second << endl;
        }
        pq.pop();
        check[now.second]=true;
        rep(i,n+2){
            if(!check[i]){
                if(chmin(d[i],d[now.second]+mat[i][now.second])){
                    pq.push(make_pair(d[i],i));
                }
            }
        }
    }
    printf("%.10lf\n",d[1]);
    return 0;
}


Measured memory_bytes: 14452
#include<stdio.h>

int main(){

    int i, a, b, c, count;

    count = 0;

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

    for ( i = a ; i <= b ; i++ ){
    	if (c%i == 0) {
    		count += 1;
    	}
    }

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

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

int main() {
  string str;
  int n = 0, h;

  while (1) {
    cin >> str;
    if (str == "-") break;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> h;
      str = str.substr(h, str.size() - h) + str.substr(0, h);
    }
    cout << str << endl;
  }
  return 0;
}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m,ans=0;
  cin >> n >> m;
  vector<long> a(m),b(m),c(m);
  vector<vector<long>> sp(n,vector<long>(n,999999999));
  for(long i=0;i<m;i++) {
    cin >> a[i] >> b[i] >> c[i];
    sp[a[i]-1][b[i]-1]=c[i];
    sp[b[i]-1][a[i]-1]=c[i];
  }
  for(long i=0;i<n;i++) sp[i][i]=0;
  for(long k=0;k<n;k++) {
    for(long i=0;i<n;i++) {
      for(long j=0;j<n;j++) {
        sp[i][j]=min(sp[i][j],sp[i][k]+sp[k][j]);
      }
    }
  }
  for(long i=0;i<m;i++) if(sp[a[i]-1][b[i]-1]!=c[i]) ans++;
  cout << ans << endl;
}

Measured memory_bytes: 3704
N, M = map(int, input().split())
D = list(map(int, input().split()))
dp = [[0] * 2551 for i in range(51)]
dp[0][0] = 1
for k in D:
    for i in range(49, -1, -1):
        for j in range(2500, -1, -1):
            dp[i+1][j + k] += dp[i][j]

ans = 0
for i in range(1, N+1):
    ans += dp[i][i*M]
print(ans)





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

using namespace std;

int N,K, A[100004],dp[100004];

int f(int i){

    if(i >=  N-1){
        return 0;
    }
    if(dp[i] != -1){
        return dp[i];
    }
    int one = abs(A[i]-A[i+1]) + f(i+1);
    for(int j = 2; j <= K; j++) {
        int js = i+j < N? abs(A[i]-A[i+j]) + f(i+j) : one;
        one = min(one,js);
        dp[i] = one;
    }
    dp[i] = one;
    return dp[i];
}

int main() {
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        dp[i] = -1;
    }
    printf("%d",f(0));
}

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

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

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

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

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

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

using piii = pair<int, PII>;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	ll a[310][310] = {};
	ll d[310][310] = {};
	cin >> N;
	ll res = 0;
	REP(i, N)	REP(j, N){
		cin >> a[i][j];
		d[i][j] = a[i][j];
		res += a[i][j];
	}

	REP(k, N) REP(i, N) REP(j, N)
		d[i][j] = min(d[i][j], d[i][k]+d[k][j]);
	REP(i, N) REP(j, N){
		if(d[i][j] != a[i][j]){
			cout << -1 << endl;
			return 0;
		}
	}

	REP(k, N){
		REP(i, N){
			REP(j, N){
				if(k == i || k == j) continue;
				if(a[i][j] == a[i][k]+a[k][j] && d[i][j] != -1){
					d[i][j] = -1;
					res -= a[i][j];
				}
			}
		}
	}

	cout << res/2 << endl;
}


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect

def LI(): return [int(x) for x in sys.stdin.readline().split()]


def I(): return int(sys.stdin.readline())


def LS(): return [list(x) for x in sys.stdin.readline().split()]


def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res


def IR(n):
    return [I() for i in range(n)]


def LIR(n):
    return [LI() for i in range(n)]


def SR(n):
    return [S() for i in range(n)]


def LSR(n):
    return [LS() for i in range(n)]


sys.setrecursionlimit(1000000)
mod = 1000000007


def solve():
    n = I()
    s = [input() for i in range(n)]
    print('AC x %s' % s.count('AC'))
    print('WA x %s' % s.count('WA'))
    print('TLE x %s' % s.count('TLE'))
    print('RE x %s' % s.count('RE'))
    return


if __name__ == "__main__":
    solve()


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

int main() {
  int n;cin>>n;
  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 a=x*x+y*y+z*z+x*y+y*z+z*x;
        if(a>n)break;
        ans[a]++;
      }
    }
  }
  for(int i=1;i<=n;i++)cout<<ans[i]<<endl;
}

Measured memory_bytes: 3644
#include<iostream> 
using namespace std;
int n,a[100005],k=0;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	    cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i)
		{
			swap(a[i],a[i+1]);
			k++;
		}
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 640
import bisect
# 操作回数を入力する
N = int(input())
# 言う数字を入力する
list_A = [int(input()) for _ in range(N)]
# 紙の状態を設定する
paper = []
# 
for A in list_A:
    if paper == []:
        paper.append(A)
        continue
    # 紙上のAをニ分探索する
    index = bisect.bisect_left(paper, A)
    if index < len(paper) and paper[index] == A:
        del paper[index]
    else:
        paper.insert(index, A)
# 結果を出力する
print(len(paper))

Measured memory_bytes: 7848
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pair<int,int>,int> ppiii;

const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int INF_INT = 1e9;

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

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

template<class TYPE>
struct edge{
    TYPE to,cost; 
    edge(TYPE t,TYPE c){
        to = t;
        cost = c;
    }
};

int main(){
    int N;
    cin >> N;
    ll res = 0;
    for(int i = 1; i <= N; i++){
        if(N % i == 0) res += N / i - 1;
        else res += N / i;
    }
    cout << res << endl;
    return 0;
}


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

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

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007 //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  REP(i,5) {
    int tmp; cin >> tmp;
    if (tmp == 0) cout << i + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3596
#include<algorithm>
#include<array>
#include<cmath>
#include<iostream>
#include<iomanip>
#include<iso646.h>
#include<queue>
#include<stack>
#include<string>
#include<vector>

#define FOR(counter,initial_value,condition) for(int counter = initial_value; counter < condition;counter++)

void insertionSort(int A[], int N) {
	FOR(i, 1, N) {
		int v = A[i];
		int j = i - 1;
		while (j >= 0 and A[j] > v) {
			A[j + 1] = A[j];
			j--;
		}
		A[j+1] = v;
	}
}

int
main()
{	
	int n;
	std::cin >> n;
	int a, b, c, d;
	a = n / 1000;
	n %= 1000;
	b = n / 100;
	n %= 100;
	c = n / 10;
	n %= 10;
	d = n;
	if ((a == b and b == c) or (b == c and c == d)) {
		std::cout << "Yes" << std::endl;
	}
	else std::cout << "No" << std::endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, L, id, A[N];
int main()
{
    scanf("%d%d", &n, &L);
    for (int i = 1; i <= n; i ++)
        scanf("%d", &A[i]);
    for (int i = 1; i < n; i ++)
        if (A[i] + A[i + 1] >= L)
            id = i;
    if (!id)
        return !printf("Impossible\n");
    printf("Possible\n");
    for (int i = n - 1; i > id; i --)
        printf("%d\n", i);
    for (int i = 1; i <= id; i ++)
        printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define left ajghkjaghkja
#define right ahgkjqhgkja

using namespace std;

const int N = 1<<20;

int n,a[N],left[N],right[N];
stack < int > s;
unsigned long long curr,ans;

int main() {
    int i,j;
    
    scanf("%d", &n);
    for(i=1;i<=n;i++) scanf("%d", &a[i]);
    for(i=1;i<=n;i++) {
        while(!s.empty() && a[s.top()]>a[i]) s.pop();
        if(s.empty()) left[i]=i-1;
        else left[i]=i-s.top()-1;
        s.push(i);
    }
    while(!s.empty()) s.pop();
    for(i=n;i>=1;i--) {
        while(!s.empty() && a[s.top()]>a[i]) s.pop();
        if(s.empty()) right[i]=n-i;
        else right[i]=s.top()-i-1;
        s.push(i);
    }
    for(i=1;i<=n;i++) {
        curr=(left[i]+1)*1llu*(right[i]+1)*1llu*a[i];
        ans+=curr;
    }
    printf("%llu\n", ans);

    return 0;
}


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

int n;
vector<pair<int, pair<int, int>>> arr;
vector<vector<int>> cache;

int get_elt(int i, int idx)
{
    if (idx == 0)
        return arr[i].first;
    else if (idx == 1)
        return arr[i].second.first;
    else
        return arr[i].second.second;
}

int solve(int i, int bit = 7)
{
    if (i > n - 1)
        return 0;
    if(cache[i][bit] != -1)
        return cache[i][bit];
    int ans = 0;
    for (int j = 0; j < 3; j++)
    {
        if ((bit & (1 << j)))
            ans = max(ans, get_elt(i, j) + solve(i + 1, 7 ^ (1 << j)));
    }
    cache[i][bit] = ans;
    return cache[i][bit];
}

int main()
{
    cin >> n;
    arr.resize(n);
    cache.assign(n + 1,vector<int>(8,-1));
    int a, b, c;
    for (int i = 0; i < n; i++)
    {
        cin >> a >> b >> c;
        arr[i] = {a, {b, c}};
    }
    cout << solve(0, 7) << endl;
    return 0;
}

Measured memory_bytes: 16256