akhauriyash/Code-Regression huggingface dataset:
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Numerics;

namespace abc173
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
            if (File.Exists("input.txt"))
            {
                Console.SetIn(new StreamReader("input.txt"));
            }
            solve_abc173A();
            Console.Out.Flush();
        }

        public static void solve_abc173C()
        {
        }

        public static void solve_abc173B()
        {
        }

        public static void solve_abc173A()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            Console.Write(n % 1000 == 0 ? 0 : 1000 - (n % 1000));
        }
    }
}

Measured memory_bytes: 28508
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int 
#define ll long long int 
#define lol std::ios::sync_with_stdio(false);std::cin.tie(NULL);cout.tie(NULL);
int main() {
    lol
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++) b[a[i]-1]=i+1;
    for(int i=0;i<n;i++) cout<<b[i]<<" "; 
    return 0;
     
}

Measured memory_bytes: 1664
#include <stdio.h>
int main(){
 char a[11];
  scanf("%s",a);
  if(a[5]=='0'){
    if(a[6]=='1'||a[6]=='2'||a[6]=='3'||a[6]=='4'){
      puts("Heisei");
    }else puts("TBD");
    return 0;
  }else puts("TBD");
 return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;

int main()
{
    int n, q;
    while (cin >> n >> q, n|q) {
        int count[100];
        fill_n((int *)count, 100, 0);
        rep(i, n){
            int m;
            cin >> m;
            rep(j, m){
                int date;
                cin >> date;
                count[date]++;
            }
        }
        int max = count[0];
        int maxdate = 0;
        rep(i, 100) {
            if (max < count[i] && count[i] >= q) {
                max = count[i];
                maxdate = i;
            }
        }
        cout << maxdate << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define ifaxb(a, x, b) if (a < x && x < b)
#define toInt(x) (x - '0')
#define vi vector<int>
#define vs vector<string>
#define all(x) x.begin(), x.end()
#define INF 2147483647
#define _INF -2147483647
#define pi 3.1415926536
#define MAXN 100004
using namespace std;
typedef long long ll;

int main() {
  int a,b;
  cin >> a >> b;
  rep(i,4){
    if(a*b*i % 2 != 0){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout  << "No" << endl;
}

Measured memory_bytes: 384
/*input
3 2
2
1 3
1
3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld double
#define pii pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define MP make_pair
ll mult(ll a,ll b){
    ll res=0LL;
    while(b){
        if(b&1) res=(res+a)%MOD;
        a=(a+a)%MOD;
        b>>=1;
    }
    return res%MOD;
}
ll mypow(ll a,ll b){
    ll res=1LL;
    while(b){
        if(b&1) res=res*a%MOD;
        a=a*a%MOD;
        b>>=1;
    }
    return res;
}
int cnt[105];
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,k;
    cin>>n>>k;
    REP(i,k){
        int x;
        cin>>x;
        REP(j,x){
            int b;
            cin>>b;
            --b;
            cnt[b]++;
        }
    }
    int ans=0;
    REP(i,n) if(!cnt[i]) ++ans;
    cout<<ans;
}

Measured memory_bytes: 3632
#pragma GCC optimize("O3") 

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

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

typedef pair<int, int>          pii;
typedef pair<ll,ll>             pll;
typedef vector<int>             vi;
typedef vector<ll>              vll;
typedef vector<pii>             vpii;
typedef vector<pll>             vpll;

#define test(t)		        int t; cin >> t; while(t--)
#define f(i, a, b)	        for(int (i) = (a); (i) < (b); ++(i))
#define all(a)		        (a).begin(), (a).end()
#define endl 		        "\n"
#define maxvec(vec)             *max_element(all(vec))
#define minvec(vec)             *min_element(all(vec))
#define maxarr(arr)             *max_element(arr, arr + n)
#define minarr(arr)             *min_element(arr, arr + n)
#define deb(x)		        cout << #x << ": " << x << endl;
#define deb2(x,y)	        cout << #x << ": " << x << " ~ " <<  #y << ": " << y << endl;
#define deba(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n << " "; cout << "]" << endl;
#define debap(arr)	        cout << #arr << " ~ [ "; for(auto n: arr) cout << n.first << "-" << n.second << " "; cout << "]" << endl;
#define fast 		        ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

#define mx9		1000000007
#define mx7		10000007
#define mx6		1000006
#define mx5		200005
#define inf		1<<30                                 
#define eps		1e-9
#define PI		3.141592653589793238462643383279502884L

void solve()
{
    ll n;
    cin >> n;
  	ll mod = 0;
    f(i, 1, 1000005)
    {
        mod = (mod * 10 + 7) % n;
        if(mod == 0)
        {
            cout << i << endl;
            return;
        }
    }
    cout << -1 << endl; 
}

int main()
{
    fast;
    // test(t)
        solve();
    return 0;
}


Measured memory_bytes: 3600
/**
 *    author:  FromDihPout
 *    created: 2020-08-10
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    const int N = 10;
    int h, w;
    cin >> h >> w;
    vector<vector<int>> c(N, vector<int> (N));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
        }
    }
    
    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }
    
    int ans = 0;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            int x;
            cin >> x;
            if (x != -1) ans += c[x][1];
        }
    }
    cout << ans << '\n';
    return 0;
}

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

N = input().rstrip()
N = N[::-1]

if N[0] == "3":
    print("bon")
elif N[0] == "0" or N[0] == "1" or N[0] == "6" or N[0] == "8":
    print("pon")
else:
    print("hon")

Measured memory_bytes: 8980
object Main {
  def main(args: Array[String]): Unit = {
    val factors           = io.StdIn.readLine.split(" ").map{_.toInt}
    val monsters_hp       = io.StdIn.readLine.split(" ").map{_.toInt}.sorted
    var all_attacks_count = 0.toLong

    (0 until monsters_hp.length - factors( 1 ) ).foreach{ i =>
      all_attacks_count += monsters_hp( i ).toLong
    }

    println( all_attacks_count )
  }
}

Measured memory_bytes: 84480
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;

int fi[512][512];

int main(void)
{
  int h, w;
  cin >> h >> w;
  REP(i, h) REP(j, w) {
    cin >> fi[i+1][j+1];
  }
  vector<tuple<int,int,int,int> > answer;
  REP(i, h) REP(j, w-1) {
    int y = i+1;
    int x = j+1;
    if(fi[y][x] % 2) {
      answer.emplace_back(y, x, y, x+1);
      ++fi[y][x+1];
    }
  }
  REP(i, h-1) {
    int y = i+1;
    int x = w;
    if(fi[y][x] % 2) {
      answer.emplace_back(y, x, y+1, x);
      ++fi[y+1][x];
    }
  }
  cout << answer.size() << endl;
  for(auto t: answer) {
    int a, b, c, d;
    tie(a, b, c, d) = t;
    cout << a << " " << b << " " << c << " " << d << endl;
  }
  return 0;
}


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

import numpy as np

cord = []

for n in range(N):
    str_list = input().split(' ')
    int_list = [int(x) for x in str_list]
    cord.append(int_list)

cord = np.array(cord)
cord_tile = np.tile(cord, (1,N))
cord_tile_ = np.reshape(cord_tile, (len(cord_tile), len(cord_tile), 2))
cord_tile_t = np.transpose(cord_tile_.copy(),(1,0,2) )


dist_mat = np.sqrt( np.sum( (cord_tile_-cord_tile_t)**2, axis=2) )

import math
facto = math.factorial(N-1)

print( np.sum(dist_mat)/N )


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

#define loop(i,a,b) for(ll i=a; i<b; i++)
#define rloop(i,a,b) for(ll i=a; i>b; i--)
#define all(var) var.begin(), var.end()
#define eloop(var) for(auto elem : var)
#define debug(x) cerr<<#x<<" ----> "<<x<<endl;
#define TT ll tt; cin>>tt; while(tt--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define INF 0x7fffffff
#define LINF 2000000000000000007
#define MOD 1000000007
#define MAX 100005
typedef long long ll;
typedef long double ld;

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

    //TT
    {
        ld h,a;
        cin>>h>>a;
        cout<<ceil(h/a);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s,t;
  cin >> s >> t;
  if(t.size()>s.size()){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  string tmp;
  bool res = false;
  int h;
  for(int i=0; i<s.size()-t.size()+1; i++){
    tmp = s.substr(i,t.size());
    //cout << t << " " << tmp << endl;
    for(int j=0; j<t.size(); j++){
      if(t.at(j) != tmp.at(j) && tmp.at(j) != '?'){
        break;
      }
      if(j==t.size()-1){
        h = i;
        res = true;
      }
    }
  }
  if(!res){
    cout << "UNRESTORABLE" << endl;
    return 0;
  }
  for(int i=0; i<s.size(); i++){
    if(s.at(i) == '?'){
      if(i>=h && i<=h+t.size()-1){
        s.at(i) = t.at(i-h);
      }else{
        s.at(i) = 'a';
      }
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		Set<Integer> set = new HashSet<Integer>();
		set.add(scan.nextInt());
		set.add(scan.nextInt());
		set.add(scan.nextInt());
		System.out.println(set.size());
	}
}

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

using namespace std;

typedef long long ll;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N;
	cin >> N;
	vector<ll> a(N + 1);
	ll sum = 0;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	a[N] = a[0];
	ll d = N * (N + 1) / 2;
	if (sum % d != 0) {
		cout << "NO" << endl;
		return 0;
	}
	sum /= d;
	vector<ll> memo(N);
	for (int i = 0; i < N; i++) {
		ll tmp = sum - (a[i + 1] - a[i]);
		if (tmp < 0 || tmp % N != 0) {
			cout << "NO" << endl;
			return 0;
		}
		tmp /= N;
		memo[N - i - 1] = tmp;
	}

	ll sum2 = 0;
	for (int i = 0; i < N; i++) {
		sum2 += memo[i];
	}

	if (sum != sum2) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,tmp;
    double ans=0;
    cin>>n;
    double num[n];
    for(int k=0;k<n;k++){
        cin>>num[k];
    }
        for (int i=0; i<n; ++i) {
            for (int j=i+1; j<n; ++j) {
                if (num[i] > num[j]) {
                    tmp =  num[i];
                    num[i] = num[j];
                    num[j] = tmp;
      }
    }
  }
  ans=num[0];
  for(int i=0;i<n-1;i++){
      ans=(ans+num[i+1])/2;
  }
  cout<<ans;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define dump(x) cout << (x) << '\n';
#define fi first
#define se second
typedef int64_t Int;
Int mod = 1e9+7;
Int INF = 1e9+7;

Int dp[10000];

int main() {
    Int n, t;
    cin >> n >> t;
    vector<pair<Int, Int>>  p(n);
    for (Int i = 0; i < n; i++) {
        cin >> p[i].fi >> p[i].se;
    }
    sort(p.begin(), p.end());
    for (Int i = 0; i < n; i++) {
        for (Int j = t - 1; j >= 0; j--) {
            dp[j + p[i].fi] = max(dp[j + p[i].fi], dp[j] + p[i].se);
        }
    }
    Int ma = 0;
    for (Int i = 0; i < 10000; i++) {
        ma = max(ma, dp[i]);
    }
    dump(ma);
    return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	private static Scanner sc;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		sc = new Scanner(System.in);
		int x=0;
		int max=0;
		int N = sc.nextInt();
		String S = sc.next();
		for(int i=0;i<N;i++){
			char s = S.charAt(i);
			if(s=='I'){
				x=x+1;
			}else if(s=='D'){
				x=x-1;
			}
			if(max<x){
				max=x;
			}		
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

int main() {
	int a, b;
	char op;

	std::cin >> a >> op >> b;

	if (op == '+') {
		std::cout << a + b << std::endl;
	}
	else {
		std::cout << a - b << std::endl;
	}
	return 0;
}

Measured memory_bytes: 256
use std::io::*;

fn main() {
  let stdin = stdin();
  let mut lines = stdin.lock().lines();

  loop {
    let n = lines.next().unwrap().unwrap().parse::<f64>().unwrap();
    if n == 0.0 { break; }

    let data = lines.next().unwrap().unwrap()
      .split_whitespace()
      .map(|s| s.parse::<f64>().unwrap())
      .collect::<Vec<_>>();

    let avg = data.iter().sum::<f64>() / n;
    let sd = (data.into_iter().fold(0.0, |acc, s| acc + (s - avg).powi(2)) / n).sqrt();

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



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

#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ll long long 
 
using namespace std;

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a,b;
	cin>>a>>b;
	if(a-2*b>0)
	cout<<a-2*b;
	else 
	cout<<"0";

	return 0;
}

Measured memory_bytes: 3656
import math
n = int(input())
l = [0 for i in range(n)]
p = min(101,math.ceil(n)+1)
for x in range(1, p):
    for y in range(1, p):
        for z in range(1, p):
            s = x**2 + y**2 + z**2 + x*y + y*z + z*x;
            if s <= n:
                l[s-1] += 1
for i in range(n):
    print(l[i])

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e3+5;
const ll mod=1e9+7;
int n;
int main(){
    cin>>n;
    int x[105],y[105];
    int flag=0;
    for(int i=0;i<n;i++) cin>>x[i]>>y[i];
    for(int i=0;i<=n-3;i++){
        if(x[i]==y[i]&&x[i+1]==y[i+1]&&x[i+2]==y[i+2]){
            flag=1;
            break;
        }
    }
    if(flag) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define INFL 0x3f3f3f3f3f3f3f3f
const int mxN=200005;
int n,m[mxN],d[mxN],k,maior,resp;

int C(int u){
    int counter=0;
    for(int i=0;i<n;i++){
        if(m[i]*d[n-i-1]>u){
            counter+=(m[i]*d[n-i-1]-u+d[n-i-1]-1)/d[n-i-1];
            if(counter>k)return 0;
        }
    }
    return 1;

}

int bb(){
    int ini=0,fim=maior,meio;
    while(ini<=fim){
        meio=(ini+fim)/2;
        //cout<<meio<<"\n";
        if(C(meio)){
            resp=meio;
            fim=meio-1;
        }
        else ini=meio+1;

    }

    cout<<resp<<"\n";
}

int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>m[i];
    }
    for(int i=0;i<n;i++){
        cin>>d[i];
    }
    sort(m,m+n);
    sort(d,d+n);

    for(int i=0;i<n;i++){
        maior=max(maior,m[i]*d[n-i-1]);
    }

    resp=maior;

    bb();


}

Measured memory_bytes: 3328
### ----------------
### ここから
### ----------------

import sys
from io import StringIO
import unittest

sys.setrecursionlimit(50000000)

class check():
    def __init__(self,n,q):
        readline=sys.stdin.readline
        self.tree=[[] for i in range(n)]
        self.ans=[0]*n
        for i in range(n-1):
            a,b=map(int, readline().rstrip().split())
            a-=1
            b-=1
            self.tree[a].append(b)
            self.tree[b].append(a)
        for i in range(q):
            p,x=map(int, readline().rstrip().split())
            p-=1
            self.ans[p]+=x
    def do(self,root,next):
        if root >= 0:
            self.ans[next]+=self.ans[root]
        for a in self.tree[next]:
            if a==root:
                continue
            self.do(next,a)
    def answer(self):
        print(" ".join(map(str,self.ans)))






def resolve():
    readline=sys.stdin.readline

    n,q=map(int, readline().rstrip().split())
    c=check(n,q)
    c.do(-1,0)
    c.answer()

    return

if 'doTest' not in globals():
    resolve()
    sys.exit()

### ----------------
### ここまで 
### ----------------

Measured memory_bytes: 234688
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const long LONG_INF = 2147483647;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int main(int argc, char const *argv[])
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vl h(n), dp(n);
    rep1(i,n){
        cin >> h[i];
    }
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);

    rrep1(i,3,n){
        int a,b;
        a = dp[i-2] + abs(h[i-2]-h[i]);
        b = dp[i-1] + abs(h[i-1]-h[i]);
        if (a <= b)
        {
            dp[i] = a;
        } else
        {
            dp[i] = b;
        }
    }
    cout << dp[n] << endl;
    return 0;
}


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

int main(){
  int k;
  string s;
    
    cin >> k >> s;
  
  int i = 0;
  int flg = 0;
  
  while(i<k-2){
    if (s.at(i) == 'A'){
      if (s.at(i+1) == 'B'){
        if (s.at(i + 2) == 'C'){
          flg = flg + 1;
        }
      }
    }
    i++;
  }
   
    cout << flg << endl;
  }

Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))
ans = 0
for i in range(N):
    while(h[i] != 0):
        ans += 1
        for j in range(i, N):
            if h[j] >= 1:  h[j] -= 1
            else:  break
print(ans)

Measured memory_bytes: 66072
from sys import stdin
input = stdin.readline

import heapq

def prim(N):
    d[1] = 0
    p[1] = -1
    u = 1

    while True:
        mincost = 3000
        for i in range(1, N+1):
            if color[i] != 2 and d[i] < mincost:
                mincost = d[i]
                u = i
        if mincost == 3000:
            break

        color[u] = 2

        for v in range(1, N+1):
            if color[v] != 2 and M[u][v] != 3000:
                if M[u][v] < d[v]:
                    d[v] = M[u][v]
                    p[v] = u
                    color[v] = 1
    
    sum_ = 0
    for i in range(1, N+1):
        if p[i] != -1:
            sum_ += M[i][p[i]]

    return sum_




N = int(input())
color = [0] * (N+1)
counter = 0
d = [3000] * (N+1) #V-T間の重み最小辺の記録
p = [-1] * (N+1)
M = [[3000] * (N+1) for i in range(N+1)]

for i in range(1, N+1):
    A = list(map(int, input().split()))
    for j, v in enumerate(A):
        if v != -1:
            M[i][j+1] = v

print(prim(N))





Measured memory_bytes: 5988
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e8;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
vector<vector<char> >in(14,vector<char>(14));
int x[4]={0,0,1,-1};
int y[4]={1,-1,0,0};
void func(int a,int b){
	in[a][b]=0;
	rep(k,4)if(in[a+x[k]][b+y[k]]!=0)func(a+x[k],b+y[k]);
}


int main(){
	char d;
	while(cin>>d){
		rep(i,12)rep(j,12){
			if(!i&&!j)in[i+1][j+1]=d;
			else cin>>in[i+1][j+1];
			if(in[i+1][j+1]=='0')in[i+1][j+1]=0;else in[i+1][j+1]=1;
		}
		int out=0;
		rep(i,12)rep(j,12)if(in[i+1][j+1]!=0){
			out++;
			func(i+1,j+1);
		}
		cout<<out<<endl;
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>//Carefully Crafted by hetp111
using namespace std;
#define int long long
#define double long double
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vii vector<pii>
#define MOD 1000000007
#define MOD2 998244353
#define MOD3 1000000009
#define PI acos(-1)
#define eps (1e-8)
#define INF (1e18)
#define FASTER ios_base::sync_with_stdio(0);cin.tie(0)
template<class A,class B>ostream&operator<<(ostream&out,const pair<A,B>&a){return out<<"("<<a.first<<","<<a.second<<")";}
template<class A>ostream&operator<<(ostream&out,const vector<A>&a){for(const A &it:a)out<<it<<" ";return out;}
template<class A,class B>istream&operator>>(istream&in,pair<A,B>&a){return in>>a.first>>a.second;}
template<class A>istream&operator>>(istream&in,vector<A>&a){for(A &i:a)in>>i;return in;}
//ifstream cinn("in.in");ofstream coutt("out.out");
int poww(const int &a,int b,const int &m=MOD){if(b==0)return 1;int x=poww(a,b/2,m);x=x*x%m;if(b&1)x=x*a%m;return x;}
int ceil(const int &a,const int &b){return (a+b-1)/b;}
////Read:
//Check corner cases, n==1;
//
////Some function:
//__builtin_popcountll(), is_sorted(),

signed main(){
    FASTER;
    int a,b,c;cin>>a>>b>>c;
    if(a+b+c>=22){
        cout<<"bust";
    }else cout<<"win";
}



Measured memory_bytes: 3612
// AOJ 2249: Road Construction
// 2017.11.15 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX 16010
typedef struct { int t, node, c; } QUE;
QUE que[MAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && (que[l].t < que[i].t ||
		que[l].t == que[i].t && que[l].c < que[i].c)) min = l; else min = i;
	if (r < qsize && (que[r].t < que[min].t ||
		que[r].t == que[min].t && que[r].c < que[min].c)) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
//	return 1;
}

void enq(int n, int t, int c)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].node = n, que[i].t = t, que[i].c = c;
	while (i > 0 && (que[min = PARENT(i)].t > que[i].t ||
		   que[min].t == que[i].t && que[min].c > que[i].c)) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x55555555
typedef struct { int to, d, c; } TBL;
TBL tbl[10001][50];
int len[10001];
char visited[10001]; int size;

int dijkstra(int start)
{
	int i, s, d, c, ans = 0;
	TBL *e;

	qsize = 0;
	memset(visited, 0, sizeof(visited));
	enq(start, 0, 0);
	while(qsize) {
		s = que[0].node, d = que[0].t, c = que[0].c; deq();
		if (visited[s]) continue;
		visited[s] = 1;
		ans += c;
		for (e = tbl[s], i = len[s]; i--; e++) {
			if (visited[e->to]) continue;
			enq(e->to, d + e->d, e->c);
		}
	}
	return ans;
}

char buf[40], *p;
int getint()
{
	int n = 0;
	while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int main()
{
	int n, m, i, u, v, d, c;
	TBL  *e;
#if TM
	clock_t start, finish;
	start = clock();
#endif

	while (fgets(p=buf, 40, stdin) && *p != '0') {
		size = n = getint(), p++, m = getint();

		memset(len, 0, sizeof(len));
		for (i = 0; i < m; i++) {
			fgets(p=buf, 40, stdin);
			u = getint()-1, p++, v = getint()-1, p++, d = getint(), p++, c = getint();

			e = tbl[u] + len[u];
			e->to = v, e->d = d, e->c = c, len[u]++;

			e = tbl[v] + len[v];
			e->to = u, e->d = d, e->c = c, len[v]++;
		}
		printf("%d\n", dijkstra(0));
	}
#if TM
	finish = clock();
	printf("time %lf\n", (double)(finish-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> s(N);
  int sum=0;
  for(int i=0; i<N; i++){
    cin >> s[i];
    sum += s[i];
  }
  if(sum%10!=0){
    cout << sum << endl;
    return 0;
  }

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

  bool flag=false;
  for(int i=0; i<N; i++){
    if(s[i]%10!=0){
      sum -= s[i];
      flag=true;
      break;
    }
  }

  cout << (flag?sum:0) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const double EPS=1e-10;
typedef double frac;
double add(double l, double r){
    if(abs(l+r)<EPS*(abs(l)+abs(r))) return 0;
    return l+r;
}
struct Pt{
    frac x, y;
    Pt(frac xx=0, frac yy=0){x=xx;y=yy;}
    Pt operator=(Pt rhs){x=rhs.x;y=rhs.y;return *this;}
    Pt operator+(Pt rhs){return Pt(add(x,rhs.x), add(y,rhs.y));}
    Pt operator-(Pt rhs){return Pt(add(x,-rhs.x), add(y,-rhs.y));}
};
Pt operator*(frac lhs, Pt rhs){return Pt(lhs*rhs.x, lhs*rhs.y);}
Pt operator*(Pt lhs, frac rhs){return Pt(rhs*lhs.x, rhs*lhs.y);}
bool operator<(Pt lhs, Pt rhs){
    return lhs.x!=rhs.x ? lhs.x<rhs.x : lhs.y<rhs.y;
}
ostream& operator<<(ostream &os, Pt rhs){
    os << rhs.x << " " << rhs.y;
    return os;
}
frac dot(Pt a, Pt b){return add(a.x*b.x,a.y*b.y);}//内積
frac cross(Pt a, Pt b){return add(a.x*b.y,-a.y*b.x);}//外積
//qが線分p1-p2上にあればtrue
bool on_seg(Pt p1, Pt p2, Pt q){
    return cross(p1-q,p2-q)==0 && dot(p1-q,p2-q)<0;
}
//intersection　交点を求める
Pt insec(Pt p1, Pt p2, Pt q1, Pt q2){
    return p1+(cross(q2-q1,q1-p1)/cross(q2-q1,p2-p1))*(p2-p1);
}
//多角形の面積を求める
frac area(vector<Pt> p){
    frac sum=0;
    int sz=p.size();
    for(int i=1; i<sz-1; ++i){
        sum += abs(cross(p[i]-p[0],p[i+1]-p[0]));
    }
    return sum/2;
}

int main(){
	int n;  cin >> n;
    vector<Pt> p(n+1);
    for(int i=0; i<n; i++){
        cin >> p[i].x >> p[i].y;
    }
    p[n]=p[0];

    int q; cin >> q;
    for(int i=0; i<q; i++){
        Pt p1, p2;
        cin >> p1.x >> p1.y >> p2.x >> p2.y;
        
        vector<Pt> poly;
        for(int j=0; j<n+1; j++){
            if(cross(p2-p1,p[j]-p1)>=0) poly.push_back(p[j]);
            if(cross(p2-p1,p[j+1]-p[j])==0) continue;
            Pt tmp=insec(p[j],p[j+1],p1,p2);
            if(on_seg(p[j],p[j+1],tmp)) poly.push_back(tmp);
        }
        cout <<fixed << setprecision(8);
        cout << area(poly) << endl;
    }
}


Measured memory_bytes: 3280
#include <iostream>

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep1(i, s, n) for (int i = s; i <= n; i++)

int A[100001];
int ans[100001];

int main()
{
	int N;

	cin >> N;
	rep1(i, 1,  N) {
		cin >> A[i];
		ans[A[i]] = i;
	}

	rep1(i, 1, N) cout << ans[i] << " ";
	cout << endl;

	return 0;
}


Measured memory_bytes: 1536
N,K = map(int, input().split())
A = list(map(int,input().split()))
MAX = 2 * 10**5+1
nxt = [-1 for i in range(MAX)]

last_index = [-1 for i in range(MAX)]
next_index = [-1 for i in range(MAX)]
first_index = [-1 for i in range(MAX)]
for i in range(N):
	a = A[i]
	last = last_index[a]
	if last >= 0:
		next_index[last] = i
	else:
		first_index[a] = i
	last_index[a] = i

start_stat = 0
while True:
	current = first_index[start_stat] + 1
	while current < N and next_index[current] != -1:
		current = next_index[current] + 1
	if current >= N:
		nxt[start_stat] = 0
		break
	else:
		stat = A[current]
		nxt[start_stat] = A[current]
		if nxt[A[current]] == -1:
			start_stat = A[current]
			continue
		else:
			break

order = [0]
in_order = [False for i in range(MAX)]
in_order[0] = True
last_stat = nxt[0]
while not in_order[last_stat]:
	order.append(last_stat)
	in_order[last_stat] = True
	last_stat = nxt[last_stat]
a,b = 0,len(order)
for x in order:
	if x == last_stat:
		break
	else:
		a += 1
		b -= 1
stat_index = K if K < a else (K-a) % b
init_status = order[stat_index]
before_stat = order[(stat_index - 1) % len(order)]
current = first_index[before_stat] + 1
if init_status == 0:
	print("")
	exit()
ans = []
while current < N:
	if next_index[current] != -1:
		current = next_index[current] + 1
	else:
		ans.append(A[current])
		current += 1
print( " ".join(list(map(str, ans))))


Measured memory_bytes: 42280
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX;
#define INFL LLONG_MAX;
typedef long long ll;
using namespace std;

int main(){
  int n; cin >> n;
  int x = n%10;

  if(x==3) puts("bon");
  else if(x==0||x==1||x==6||x==8) puts("pon");
  else puts("hon");
}


Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[MM],nxt[MM];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 777777
#define MM 50000000
pii ps[SZ]; int pn=0;
int dd(pii a,pii b) {return (a.fi-b.fi)*(a.fi-b.fi)+(a.se-b.se)*(a.se-b.se);}
int n,d1,d2;
namespace A
{
Edg
int col[SZ];
void dfs(int x)
{
	for esb(x,e,b) if(col[b]==-1)
		col[b]=1-col[x],dfs(b);
}
void paint()
{
	memset(col,-1,sizeof col);
	for(int i=1;i<=pn;++i) if(col[i]==-1)
		col[i]=0,dfs(i);
}
}
namespace B
{
Edg
int col[SZ];
void dfs(int x)
{
	for esb(x,e,b) if(col[b]==-1)
		col[b]=1-col[x],dfs(b);
}
void paint()
{
	memset(col,-1,sizeof col);
	for(int i=1;i<=pn;++i) if(col[i]==-1)
		col[i]=0,dfs(i);
}
}
int pr[777][777],sq[2333333];
vector<pii> ts[2][2];
int main()
{
	memset(sq,-1,sizeof sq);
	//cerr<<sizeof(A::vb)*4/1024.0/1024.0<<"M\n";
	cin>>n>>d1>>d2;
	for(int i=0;i<n+n;i++) sq[i*i]=i;
	for(int i=0;i<n+n;i++)
		for(int j=0;j<n+n;++j) ps[++pn]=pii(i,j),pr[i][j]=pn;
	for(int i=1;i<=pn;++i)
	{
		for(int j=0;j<n+n;++j)
		{
			int dx=d1-(j-ps[i].fi)*(j-ps[i].fi);
			if(dx<0) continue;
			int w=sq[dx];
			if(w==-1) continue;
			{
			int t=ps[i].se-w;
			if(t>=0&&t<n+n)
			{
			int jj=pr[j][t];
			if(dd(ps[i],ps[jj])==d1) A::ad_de(i,jj);
			}
			}
			{
			int t=ps[i].se+w;
			if(t>=0&&t<n+n)
			{
			int jj=pr[j][t];
			if(dd(ps[i],ps[jj])==d1) A::ad_de(i,jj);
			}
			}
		}
	}
	for(int i=1;i<=pn;++i)
	{
		for(int j=0;j<n+n;++j)
		{
			int dx=d2-(j-ps[i].fi)*(j-ps[i].fi);
			if(dx<0) continue;
			int w=sq[dx];
			if(w==-1) continue;
			if(w*w!=dx) continue;
			{
			int t=ps[i].se-w;
			if(t>=0&&t<n+n)
			{
			int jj=pr[j][t];
			if(dd(ps[i],ps[jj])==d2) B::ad_de(i,jj);
			}
			}
			{
			int t=ps[i].se+w;
			if(t>=0&&t<n+n)
			{
			int jj=pr[j][t];
			if(dd(ps[i],ps[jj])==d2) B::ad_de(i,jj);
			}
			}
		}
	}
	A::paint(); B::paint();
	for(int i=1;i<=pn;++i)
		ts[A::col[i]][B::col[i]].pb(ps[i]);
	int a=0,b=0;
	for(int x=0;x<2;++x)
		for(int y=0;y<2;++y)
			if(ts[x][y].size()>=n*n) a=x,b=y;
	for(int i=0;i<n*n;++i)
		printf("%d %d\n",ts[a][b][i].fi,ts[a][b][i].se);
}


Measured memory_bytes: 148084
<?php

$a=explode(' ',trim(fgets(STDIN)));
if($a[0]==$a[1]){
        echo "a == b".PHP_EOL;
}else if($a[0]>$a[1]){
        echo "a > b".PHP_EOL;
}else {
        echo "a < b".PHP_EOL;
}

Measured memory_bytes: 6540
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
        new Main().run();
    }
	int J;
	int O;
	int I;
	int max;
	char t;
	public void run(){
		Scanner scan = new Scanner(System.in);
		while(scan.hasNext()){
			String str = scan.nextLine();
			if(str.indexOf("J") < 0 || str.indexOf("O") < 0 || str.indexOf("I") < 0){
				System.out.println(0);
				continue;
			}
			J = 0;
			O = 0;
			I = 0;
			max = 0;
			for(int i = 0;i < str.length();i++){
				t = str.charAt(i);
				if(t == 'J'){
					if(I > 0){
						max = Math.max(max,(O > I)?0:Math.min(I,Math.min(O,J)));
						J = 0;
						O = 0;
						I = 0;
					}else if(O > 0){
						J = 0;
						O = 0;
					}
					J++;
				}else if(t == 'O'){
					if(I > 0){
						max = Math.max(max,(O > I)?0:Math.min(I,Math.min(O,J)));
						J = 0;
						O = 0;
						I = 0;
					}else if(J > 0){
						O++;
						if(J < O){
							J = 0;
							O = 0;
						}
					}
				}else if(t == 'I'){
					if(J > 0 && O > 0){
						I++;
					}else{
						J = 0;
						O = 0;
						I = 0;
					}
				}
			}
			if(I > 0){
				max = Math.max(max,(O > I)?0:Math.min(I,Math.min(O,J)));
			}
			System.out.println(max);
		}
	}
}

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

int main(){
  int m; cin >> m;
  ll D = 0; ll S = 0;
  for(int i = 0; i < m; i++){ 
    ll d,c; cin >> d >> c;
    D += c;
    S += d*c;
  }
  
  cout << (D-1)+(S-1)/9 << endl;
  
  return 0;
}

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

int main(){
	static int n;
	static int a[100010],b[100010],c[100010];
	scanf("%d",&n);
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&a[i]);
	}
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&b[i]);
	}
	for(int i = 0 ; i < n ; i ++){
		scanf("%d",&c[i]);
	}
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
	
	long long ret = 0;
	for(int i = 0 ; i < n ; i ++){
		long long x = lower_bound(a,a+n,b[i])-a;
		long long y = (c+n)-lower_bound(c,c+n,b[i]+1);
		ret += x*y;
	}
	cout << ret << endl;
}



Measured memory_bytes: 1408
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.List
import Data.Maybe
import Data.Bits
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B

modulus :: Int
modulus = 10^9 + 7

query :: B.ByteString -> (Int,Int,Int,Int)
query = (`B.foldl'` (1,0,0,0))
  $ (\(!n,!na,!nab,!nabc) s ->
        case s of
          'A' -> (n, md' $ na+n, nab, nabc)
          'B' -> (n, na, md' $ na+nab, nabc)
          'C' -> (n, na, nab, md' $ nab+nabc)
          '?' -> (md $ 3*n, md $ 3*na + n, md $ 3*nab + na, md $ 3*nabc + nab)
          _   -> undefined)
 where
   md' k = if k >= modulus then k-modulus else k
   md = (`mod` modulus)

main :: IO ()
main = do
  (_,_,_,answer) <- query <$> B.getLine
  putStrLn $ show $ answer

Measured memory_bytes: 1148
#include <cstdio>
#include <vector>

void paint(std::vector<std::vector<int>> &v, int u, int d, int l, int r) {
  for (int i=u; i<d; ++i)
    for (int j=l; j<r; ++j)
      v[i][j] = 1;
}

int main() {
  int W, H, N;
  scanf("%d %d %d", &W, &H, &N);
  std::vector<std::vector<int>> canvas(H, std::vector<int>(W));

  for (int i=0; i<N; ++i) {
    int x, y, a;
    scanf("%d %d %d", &x, &y, &a);

    switch (a) {
    case 1:
      paint(canvas, 0, H, 0, x);
      break;
    case 2:
      paint(canvas, 0, H, x, W);
      break;
    case 3:
      paint(canvas, 0, y, 0, W);
      break;
    case 4:
      paint(canvas, y, H, 0, W);
    }
  }

  int res=0;
  for (int i=0; i<H; ++i)
    for (int j=0; j<W; ++j)
      if (canvas[i][j] == 0)
        ++res;

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf = numeric_limits<ll>::max()/3;

int main(void){
  int n;
  vector< P > v;
  vector< int > res;
  cin >> n;
  res.resize(n);
  for(int i = 0;i < n;++i){
    int tmp;
    cin >> tmp;
    v.push_back(P(tmp,i));
  }
  sort(v.begin(),v.end());
  for(int i = 0;i < n;++i){
    int j = v[i].second;
    if(i < n/2)
      res[j] = v[n/2].first;
    else
      res[j] = v[(n-1)/2].first;
  }
  for(int i = 0;i < n;++i)
    cout << res[i] << endl;
  return 0;
}


Measured memory_bytes: 4720
while True:
	l = input()
	L = l.split()
	for i in range(len(L)):
		L[i] = int(L[i])
	if L[0] == 0:
		break	
	a = [L[0]-number for number in range(L[0])]
	for j in range(L[1]):
		r = input()
		R = r.split()
		for k in range(len(R)):
			R[k] = int(R[k])
		b = []
		b += a[R[0]-1:R[0]+R[1]-1]
		b += a[:R[0]-1]
		b += a[R[0]+R[1]-1:]
		a.clear()
		a = b.copy()
	print(a[0])


Measured memory_bytes: 5620
n=gets.to_i
p=gets.split.map &:to_i
sorted=(1..n).to_a
n.times{|i|
    n.times{|j|
        p[i],p[j] = p[j],p[i]
        if p == sorted
            puts "YES"
            exit
        end
        p[i],p[j] = p[j],p[i]
    }
}
puts "NO"

Measured memory_bytes: 3836
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define type1 0 // 4の倍数
#define type2 1 // 4の倍数ではないが2の倍数
#define type3 2 // 奇数

int get_type(long int num) {
	if(num % 2 == 1)
		return 2;
	else if(num % 4 == 0)
		return 0;
	else
		return 1;
}

int main(void) {
	long int array[100000];
	int k, s, g, i = 0, N;
	char s1[2000000];
	char *tok;

	scanf("%d", &N);
	gets(s1);
	gets(s1);

	tok = strtok(s1, ". ");
	array[i++] = atol(tok);
	while(1) {
		tok = strtok(NULL, ". ");
		if(tok == NULL)
			break;
		array[i++] = atol(tok);
	}

	for(i = 0; i < N; i++) {
		array[i] = get_type(array[i]);
		switch(array[i]) {
			case type1:
				s++;
				break;
			case type2:
				g++;
				break;
			default:
				k++;
		}
	}
	
	if(k == s + 1) {
		if(k + s == N)
			printf("Yes");
		else
			printf("No");
	}
	else if(k == s) {
		printf("Yes");
	}
	else if(k > s) {
		printf("No");
	}
	else {
		printf("Yes");
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 2816
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
#include<numeric>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
#define mkp(a,b) make_pair(a,b)
using namespace std;

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	// This is code taken from geeksforgeek
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	// This is code taken from geeksforgeek
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}
bool check(ll a)
{
	ll count = 0;
	while (a % 2 == 0)
	{
		a /= 2;
		count += 1;
	}
	if (count > 1)
		return false;
	bool flag = true;
	for (ll i = 3; i <= sqrt(a); i += 2)
	{
		if (a % i == 0)
		{
			flag = false;
			break;
		}
	}
	return flag;
}
ll sum(ll n)
{
	return (n * (n + 1)) / 2;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	unordered_set<ll> p;
	ll x,n;
	cin>>x>>n;
	f(i,0,n)
	{
		ll temp;
		cin>>temp;
		p.insert(temp);
	}
	f(i,0,200)
	{
		if(p.find(x-i)==p.end())
		{
			cout<<x-i;
			break;
		}
		if(p.find(x+i)==p.end())
		{
			cout<<x+i;
			break;
		}

	}
	return 0;
}

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

using namespace std;
using ll = long long;

ll subCount(vector<ll> vec, ll k, int n){
    unordered_map<ll,ll> mod; 
    vector<ll> cumsum;
    mod[0] = 1; cumsum.push_back(0);
    ll result = 0, cm = 0;
    int j=0;
    for (int i = 1; i <= vec.size(); i++) { 
        if(i - j >= k){
            mod[cumsum[j]]--;
            j++;
        }
        cm += vec[i-1];
        cumsum.push_back(cm % k);
        result += mod[cm % k];
        mod[cm % k]++; 
    } 
    return result; 
}

int main(){
    ll n, k;
    cin>>n>>k;
    vector<ll> vec(n);
    for(int i=0; i<n; i++) {cin>>vec[i]; vec[i]--;}
    cout<<subCount(vec, k, n);
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;
typedef vector < vector<ll> > Mat;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  if (N % 2 == 0) return Pow(A * A % MOD, N / 2);
  return Pow(A * A % MOD, N / 2) * A % MOD;
}

ll fac[2005], rev[2005];

int main(){
  int S; cin >> S;
  fac[0] = 1; rev[0] = 1;
  for (ll i = 1; i <= S; i++){
    fac[i] = fac[i-1] * i % MOD;
    rev[i] = Pow(fac[i], MOD - 2);
  }

  ll ans = 0;
  for (int i = 1; S - 2 * i - 1 >= 0 && S - 3 * i >= 0; i++){
    ll now = fac[S - 2 * i - 1] * rev[S - 3 * i] % MOD;
    now *= rev[i-1]; now %= MOD;
    ans += now; ans %= MOD;
  }
  cout << ans << endl;

  return 0;
}


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

using namespace std;
typedef long long ll;

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;
    if (x == w / 2 && y == h / 2) cout << w * h / 2 << " " << 1 << endl;
    else cout << w * h / 2 << " " << 0 << endl;
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let s = read::<String>().chars().collect::<Vec<_>>()[0];
    let t = std::char::from_digit(s.to_digit(36).unwrap() + 1, 36).unwrap();
    println!("{}", t);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

int main() {
  vector<int> data(5);
  for (int i = 0; i < 5; i++) {
    cin >> data.at(i);
  }
  for (int i = 0; i < 5; i++){
    if(data.at(i) == (i+1))
    {
      continue;
    }else{
      cout << i+1 <<endl;
      break;
    }
  }
  
}

Measured memory_bytes: 3592
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll fa[200001],ra[200001],n,a,b,ans;
map<ll,ll>mx,my;
ll find(ll x){
    if(x==fa[x])return fa[x];
    return fa[x]=find(fa[x]);
}
void uni(ll x,ll y){
    x=find(x),y=find(y);
    if(x==y)return ;
    if(ra[x]<ra[y])swap(x,y);
    fa[y]=x;
    if(ra[x]==ra[y])ra[x]++;
}
int main(void){
    cin>>n;
    for(int i=0;i<200001;i++)fa[i]=i;
    for(int i=0;i<n;i++){
        cin>>a>>b;
        uni(a,b+100000);
    }
    for(int i=1;i<=100000;i++)mx[find(i)]++;
    for(int i=100001;i<=200000;i++)my[find(i)]++;
    for(int i=1;i<=100000;i++)ans+=mx[i]*my[i];
    cout<<ans-n<<endl;
}


Measured memory_bytes: 21248
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int sum(int n) {
    int ret = 0;
    int i = 1;
    while (true) {
        int tens = pow(10, i);
        ret += n % tens;
        n = n / tens;
        if (n == 0)
            return ret;
    }
}
int main() {
    int n;
    cin >> n;
    int sum_digits = sum(n);
    string ret = n % sum_digits == 0 ? "Yes" : "No";
    cout << ret << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
using namespace std;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;



int main(void){
    ll n;
    ll a[100000];
    cin>>n;
    rep(i,n)cin>>a[i];
    long long ans=0;
    
    rep(i,n){
        rep(j,30){
            if (a[i]%2==1)break;
            ans+=1;
            a[i]/=2;
        }
    }
    
    cout<<ans;
}

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

int cnt[10];

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

    for (int i = 0; i < 3; i++) {
        int x;
        cin >> x;
        cnt[x]++;
    }
    for (int i = 1; i <= 9; i++) {
        if (cnt[i] == 2) {
            cout << "Yes\n";
            return 0;
        }
    }
    cout << "No\n";
}

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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli n;
vll a;
vll b;
lli ans = 0;

int main(){
  cin >> n;
  a = vll(n);
  for(lli i = 0;i < n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  if(n%2 == 0){
    ans -= accumulate(a.begin(),a.begin()+n/2,0ll)*2;
    ans += accumulate(a.begin()+n/2,a.end(),0ll)*2;
    ans += a[n/2-1];
    ans -= a[n/2];
  }else{
    ans -= accumulate(a.begin(),a.begin()+n/2,0ll)*2;
    ans += accumulate(a.begin()+n/2+1,a.end(),0ll)*2;
    ans += a[n/2-1];
    ans -= a[n/2+1];
    ans += max(a[n/2]-a[n/2-1], -a[n/2]+a[n/2+1]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1024