akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using static System.Console;
using static System.Math;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var n = IO.ReadInt;
            var p = IO.ReadSplitInt;
            int min = n;
            int cnt = 0;
            for (int i = 0; i < p.Count; i++)
            {
                if (min >= p[i])
                {
                    cnt++;
                    min = p[i];
                }
            }
            WriteLine(cnt);
        }

        public class IO
        {
            #region Input
            public static string ReadString => ReadLine();
            public static int ReadInt => int.Parse(ReadLine());
            public static long ReadLong => long.Parse(ReadLine());
            public static double ReadDouble => double.Parse(ReadLine());

            public static List<string> ReadSplitString => ReadLine().Split().ToList();
            public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
            public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
            public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
            #endregion

            #region Output
            public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
            public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

            #endregion
        }

        public class Mod
        {
            #region
            private readonly static long M = 1000000007;

            public static long Add(long a, long b) => (a * b) % M;
            public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
            public static long Multi(long a, long b) => (a * b) % M;
            #endregion
        }

        public static long GCD(long x, long y)
        {
            #region
            if (x < y)
            {
                var tmp = x;
                x = y;
                y = tmp;
            }
            while (true)

            {
                if (x % y == 0)
                {
                    return y;
                }
                else
                {
                    var tmp = x;
                    x = y;
                    y = tmp % y;
                }
            }
            #endregion
        }

        public static long Choice2(long n)
        {
            #region
            if (n <= 1)
                return 0;
            if (n == 2)
                return 1;
            else
                return n * (n - 1) / 2;
            #endregion
        }
    }
}

Measured memory_bytes: 33500
#include<iostream>
using namespace std;
int main(){
int h,ans;
while(cin>>h,h){
ans=0;
int t[200][5]={{0},{0}};
for(int i=0;i<h;i++)for(int j=0;j<5;j++)cin>>t[i][j];
while(1){
bool f=1;
for(int i=0;i<h;i++){
int c=0,fi=-1;
for(int j=0;j<3;j++){
if(t[i][j]==t[i][j+1]&&t[i][j]==t[i][j+2]&&t[i][j]!=0){
c++;
if(fi==-1)fi=j;
}
}
if(c!=0)ans+=t[i][fi]*(2+c),f=0;
if(c!=0)for(int j=0;j<2+c;j++)t[i][fi+j]=0;
}
if(f)break;
for(int i=h-2;i>=0;i--){
for(int j=0;j<5;j++){
int ti=i;
while(true){
if(ti==h-1||t[ti+1][j]!=0)break;
t[ti+1][j]=t[ti][j];
t[ti][j]=0;
ti++;
}
}
}
}
cout<<ans<<endl;
}
return 0;
}

Measured memory_bytes: 1160
using System;
using System.IO;
using System.Linq;

namespace AtCoder.R170.A
{
    public static class Solver
    {
        public static void Main()
        {
            using (var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false })
            {
                Solve(Console.In, sw);
            }
        }

        public static void Solve(TextReader tr, TextWriter tw)
        {
            WriteAnswer(tw, Parse(tr));
        }

        private static void WriteAnswer(TextWriter tw, string answer)
        {
            tw.WriteLine(answer);
        }

        private static string Parse(TextReader tr)
        {
            var a = tr.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            return Calc(a);
        }

        public static string Calc(int[] a)
        {
            return string.Format("{0}", 1 + Array.FindIndex(a, x => x == 0));
        }
    }
}


Measured memory_bytes: 28336
import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val b = new ArrayBuffer[Int]
  val n = readInt
  var score = 0
  var out = 0
  var hit = 0
  for(i<-1 to n) {
    hit=0
    out=0
    score=0
    while(out!=3) {
      val s = readLine
      if(s=="OUT") out += 1
      else if(s=="HIT") {
        if(hit==3) score += 1
        else hit += 1
      } else {
        score = score+hit+1
        hit = 0
      }
    }
    b += score
  }
  println(b.mkString("\n"))
}

Measured memory_bytes: 43600
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    bool visited[n]={false};
    int refs[n];
    vector<vector<int>> graph(n);
    int i,j, a, b;
    for(i=0;i<m;i++){
        cin >> a >> b;
        graph[a-1].push_back(b-1);
        graph[b-1].push_back(a-1);
    }
    visited[0]=true;
    vector<int> v;
    v.push_back(0);
    for(i=0;i<n;i++){
        for(j=0;j<graph[v[i]].size();j++){
            //cout << i << "," << graph[v[i]][j] << endl;
            if(!visited[graph[v[i]][j]]){
                visited[graph[v[i]][j]]=true;
                v.push_back(graph[v[i]][j]);
                refs[graph[v[i]][j]]=v[i];
            }

        }
    }
    cout << "Yes" << endl;
    for(i=1;i<n;i++){
        cout << refs[i]+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 10700
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def cross3(a, b, c):
    return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0])
def solve():
    for line in readlines():
        xa, ya, xb, yb, xc, yc, xd, yd = map(float, line.split(","))
        P = [(xa, ya), (xb, yb), (xc, yc), (xd, yd)]
        D = []
        for i in range(4):
            p0 = P[i-2]; p1 = P[i-1]; p2 = P[i]
            D.append(cross3(p0, p1, p2))
        if all(e > 0 for e in D) or all(e < 0 for e in D):
            write("YES\n")
        else:
            write("NO\n")
solve()



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

int H, W, N;
int sy, sx;
string s, t;

// solve(+へ向かう座標の文字, -へ向かう座標の文字, 座標の最大値, スタート座標)
bool solve(char cRight, char cLeft, int Max, int start) {
  int left = 1, right = Max;
  // 高橋の一番最後の手（青木の最後の手は無視して良い）
  if (s[N-1] == cRight) right--;
  if (s[N-1] == cLeft) left++;

  for (int i = N-2; i >= 0; i--) {
    // 青木
    if (t[i] == cRight) {
      left = max(1, left - 1);
    }
    if (t[i] == cLeft) {
      right = min(Max, right + 1);
    }

    // 高橋
    if (s[i] == cRight) {
      right--;
    }
    if (s[i] == cLeft) {
      left++;
    }

    // 青木が移動できる範囲がなくなったら終了
    if (left > right) return false;
  }

  // スタートが[left, right]の範囲内にあれば青木の勝ち
  return left <= start and start <= right;
}

int main() {
  cin >> H >> W >> N;
  cin >> sy >> sx;
  cin >> s >> t;

  bool a1 = solve('R', 'L', W, sx); // 横方向
  bool a2 = solve('D', 'U', H, sy); // 縦方向
  bool ans = a1 and a2;

  puts(ans ? "YES" : "NO");

  return 0;
}

Measured memory_bytes: 776
N = int(input())
A = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[N-1])

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>

int main() {
  size_t N;
  std::string S;
  std::cin >> N >> S;

  int res = 0;
  for (size_t i = 1; i+1 < N; ++i) {
    int cur = 0;
    std::string s = S.substr(0, i);
    std::string t = S.substr(i);
    for (char c = 'a'; c <= 'z'; ++c)
      if (std::count(s.begin(), s.end(), c) && std::count(t.begin(), t.end(), c))
        ++cur;

    res = std::max(res, cur);
  }
  std::cout << res << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> snuke(n);
  int d,a;
  rep(i,k){
    cin>>d;
    rep(j,d){
    cin>>a;
      snuke[a-1]++;
    }
  }
  int ans=0;
  rep(i,n){
   if(snuke[i]==0) ans++;
  }
  cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 3600
n = int(input())

a = list(map(int,input().split()))

d = dict()

for i in range(n):
    if d.__contains__(a[i]):
        d[a[i]]+=1
    else:
        d[a[i]] =1
res = 0
for num,cnt in list(d.items()):
    if cnt>=num:
        res += cnt-num
    else:
        res += cnt 

print(res)


Measured memory_bytes: 20980
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	vector<int> A(3);
	cin >> A[0] >> A[1] >> A[2];
	sort(A.begin(), A.end());
	cout << abs(A[0] - A[1]) + abs(A[1] - A[2]) << endl;
	return 0;
}

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

typedef long long int ll;

int main()
{
	ll n,m;
	scanf("%lld %lld",&n,&m);
	ll arr[m];
	ll sum=0;
	for(ll i=0;i<m;i++)
	{
		scanf("%lld",&arr[i]);
		sum+=arr[i];
	}
	if(n>=sum)
		printf("%lld\n",n-sum);
	else
		printf("-1\n");
}



Measured memory_bytes: 3892
#include <iostream>
#include <string>
#include <cstdlib>
#include <stack>

using namespace std;

int main() {

  string op;
  stack<int> st;  
  int sec,fir;

  while(cin >> op){
    if(op=="+"||op=="-"||op=="*"){
      fir = st.top();
      st.pop();
      sec = st.top();
      st.pop();
      if(op=="+") st.push(fir+sec);
      if(op=="-") st.push(sec-fir);
      if(op=="*") st.push(fir*sec);
    }
    else st.push(atoi(op.c_str()));
  }
  cout << st.top() << endl;
  
}


Measured memory_bytes: 3204
#include<iostream>
#include<queue>

using namespace std;

#define rep(i, n) for (int i = 0; i < int(n); ++i)

int dp[333];

int main() {
  int s, d, m;
  while (cin >> s >> d >> m) {
    vector<pair<int, int> > sw[s];
    rep (i, s) {
      int k;
      cin >> k;
      rep (j, k) {
	int w, p;
	cin >> w >> p;
	sw[i].push_back(make_pair(w, p));
      }
    }
    rep (i, m + 1) dp[i] = 0;
    rep (i, d) {
      int f;
      cin >> f;
      rep (j, sw[f].size()) {
	for (int k = m; k - sw[f][j].second >= 0; --k) {
	  dp[k] = max(dp[k], dp[k - sw[f][j].second] + sw[f][j].first);
	}
      }
    }
    pair<int, int> res;
    res.first = 0;
    res.second = 0;
    rep (i, m + 1) {
      if (res.first < dp[i]) {
	res.first = dp[i];
	res.second = i;
      }
    }
    cout << res.first << " " << res.second << endl;
  }
  return 0;
}

Measured memory_bytes: 1232
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int inR, inC;
        int[][] spd;

        inR = Integer.parseInt(scan.next());
        inC = Integer.parseInt(scan.next());

        spd = new int[inR + 1][inC + 1];

        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                spd[i][j] = 0;
            }
        }


        for (int i = 0; i < inR; i++) {
            for (int j = 0; j < inC; j++) {
                spd[i][j] = Integer.parseInt(scan.next());
                spd[inR][j] += spd[i][j];
                spd[i][inC] += spd[i][j];
                spd[inR][inC] += spd[i][j];
            }
        }
        for (int i = 0; i < inR + 1; i++) {
            for (int j = 0; j < inC + 1; j++) {
                System.out.print(spd[i][j]);
                if (j != inC) System.out.print(" ");
            }
            System.out.print("\n");
        }
    }
}



Measured memory_bytes: 37820
#!/usr/bin/env pypy3


def get_line():
    return input()


def get_tokens():
    return get_line().split()


def get_ints():
    return [int(_) for _ in get_tokens()]


def main():
    a, b = get_ints()
    ans = a * b % 2 == 1
    print('Yes' if ans else 'No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define _h cout<<"here"<<endl;
#define fill(a,v) memset(a,v,sizeof(a));
#define all(v) v.begin(),v.end()
#define rep(i,n) for(int i=0;i<n;i+=1)
#define prd(a,n) rep(i,n) cout<<a[i]<<" \n"[i==n-1];// printf("%s\n"," " );
#define ff first
#define ss second
#define pu push_back
const int inf = 1e9+10;
const ll INF = 2e18+10;
const int Mod = 1e9+7;
const int MAXN = 1000010;
const int N=3e3+10;
const int M=210;
const int M1=1e9+7;
const int M2=1e9+9;
const int base=131;
int main()
{
  ios::sync_with_stdio(0), cin.tie(0); cout.tie(0);
  // freopen("input.txt","r",stdin);
  // freopen("output.txt","w",stdout);
  int n,x,t;
  cin>>n>>x>>t;
  int ans=0;
  ans=(n/x)*t;
  if((n%x)!=0) ans+=t;
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 3648
while True:
    tmp = input().split(' ')
    n = int(tmp[0])
    q = int(tmp[1])
    if n == 0 and q == 0:
        break
    a = []
    d = [0]*100
    for i in range(n):
        a = input().split(' ')
        for j in range(int(a[0])):
            qq = int(a[ j+1 ])
            d[qq] = d[qq] + 1
    mx = max(d)
    if mx < q:
        print(0)
    else:
        for i in range(len(d)):
            if mx == d[i]:
                print( i )
                break

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

int main(){
   long long int a[10000];
   int n;
   cin>>n;
   for(int a0=0;a0<n;a0++){
   cin>>a[a0];}
   long long int max=a[0];
   long long int min=a[0];
   long long int tot=0;
   for(int a0=0;a0<n;a0++){
   if(a[a0]<min){min=a[a0];}
   if(a[a0]>max){max=a[a0];}
   tot+=a[a0];}
   cout<<min<<" "<<max<<" "<<tot<<endl;
   return 0;
	}


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

int main() {
    long long N, T; cin >> N >> T;
    long long t[N];
    for (int i = 0; i < N; i++)
    {
        cin >> t[i];
    }

    long long ans = 0;
    for (int i = 1; i < N; i++)
    {
        ans += min(T, t[i] - t[i-1]);
    }
    ans += T;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#!/usr/bin/env python3
def main():
    from collections import deque

    N, M = map(int, input().split())
    friends_input = [set() for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        friends_input[a - 1].add(b - 1)
        friends_input[b - 1].add(a - 1)

    seen = [False] * N
    friends_group = []
    for i in range(N):
        if seen[i]:
            continue
        q = deque([i])
        tmp_group = set([i])
        while q:
            now = q.popleft()
            if seen[now]:
                continue
            seen[now] = True
            for j in friends_input[now]:
                if not seen[j]:
                    q.append(j)
                    tmp_group.add(j)
        friends_group.append(tmp_group)
    ans = 0
    for i in friends_group:
        ans = max(ans, len(i))
    print(ans)


if __name__ == '__main__':
    main()


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

int Partition(int A[], int st, int en) {
	int key = A[en];
	int smallPoint = st - 1;
	for (int i = 0; i < en; i++) {
		if (A[i] <= key) {
			smallPoint++;
			swap(A[smallPoint], A[i]);
		}
	}
	smallPoint++;
	swap(A[smallPoint], A[en]);
	return smallPoint;
}

int main() {
	int A[100000];
	int numA;
	cin >> numA;
	for (int i = 0; i < numA; i++) {
		cin >> A[i];
	}

	int key = Partition(A, 0, numA-1);

	for (int i = 0; i < numA; i++) {
		if (i) cout << " ";
		if (i == key) cout << "[";
		cout << A[i];
		if (i == key) cout << "]";
	}
	cout << endl;;
	return 0;
}

Measured memory_bytes: 3364
#include <sstream>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <string>
#include <cassert>
#include <ctime>
#include <map>
#include <math.h>
#include <cstdio>
#include <set>
#include <deque>
#include <memory.h>
#include <queue>

#pragma comment(linker, "/STACK:64000000")
typedef long long ll;

using namespace std;

const int MAXN = 1 << 18;
const int MOD = 1; // 1000 * 1000 * 1000 + 7;
const int INF = 2e9;

int main() {
#ifdef _MSC_VER
	freopen("input.txt", "r", stdin);
#endif

	string t = "CODEFESTIVAL2016";
	string s;
	while (cin >> s) {
		int n = 16;
		int ans = 0;
		for (int i = 0; i < n; i++) {
			ans += s[i] != t[i];
		}
		cout << ans << endl;
	}

	return 0;
}

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

// clang-format off
#define forn(i, x, y) for(int i = x; i < y; i++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(NULL)
// clang-format on

using LL = long long;
using VI = vector<int>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;

int main()
{
  IOS;
  int N;
  cin >> N;

  VI A(N);
  forn(i, 0, N) cin >> A[i];

  VLL dp(N, 0);
  for (int i = 0; i < N; i++)
  {
    dp[i] = A[i];
    for (int j = i - 1; j >= 0; j--)
      dp[j] = max(A[j] - dp[j + 1], A[i] - dp[j]);
  }
  cout << dp[0] << endl;

  return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <string>

int main(int argc, char *argv[])
{
    int n;

    std::cin >> n;

    if ((n / 100 == 7) || ((n / 10) % 10 == 7) || (n % 10 == 7)) {
        std::cout << "Yes" << std::endl;
    } else {
        std::cout << "No" << std::endl;
    }
    
    return 0;
}


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

map<int, int> mp;
vector<int> v;
int n;

int main() {
#ifdef HOME
	freopen("agc3c.in", "r", stdin);
	freopen("agc3c.out", "w", stdout);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	int ant(0);

	cin >> n;
	v.resize(n);
	for (auto &i: v)
		cin >> i;

	for (int i = 0; i < n; i+= 2)
		mp[v[i]]+= 1;

	sort(begin(v), end(v));
	for (int i = 0; i < n; i+= 2)
		mp[v[i]]-= 1;

	for (auto i: mp)
		ant+= int(i.second != 0);

	cout << ant / 2 << endl;

	return 0; }


Measured memory_bytes: 5376
#include <stdio.h>

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

    while(1){
        scanf("%d %c %d", &a, &op, &b);
        if(op == '?')break;

        int res;

        switch(op){
            case '+':
                res = a + b;
                break;
            case '-':
                res = a - b;
                break;
            case '*':
                res = a * b;
                break;

            case '/':
                res = a / b;
                break;
        }

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


Measured memory_bytes: 2140
function Main(input) {
  input = input.split("\n");
  var n = input[0];
  var ans;
  if(n==1){
    ans="Hello World";
  }else{
    var a= parseInt(input[1]);
    var b= parseInt(input[2]);
    ans=a+b;
  }
  console.log('%s', ans);
}
  
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(){
  var input = document.getElementById("input").value;
  Main(input);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main()
{
    int a,b,i;
    string s,t,u;
    cin>>s>>t;
    cin>>a>>b;
    cin>>u;

    if(s.compare(u)==0)
    {
        cout<<a-1<<" "<<b<<endl;
    }
    else
    {
        cout<<a<<" "<<b-1<<endl;
    }
}

Measured memory_bytes: 256
# 解説みた
# わかったけど導けないなあ
n,k=map(int,input().split())
if k==0:
    print(n*n)
    exit()
cnt=0
for b in range(k+1,n+1):
    cnt+=(b-k)*(n//b)+max(0,n%b-k+1)
print(cnt)

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

int main() {

  long long N, W;
  cin >> N >> W;

  long long wList[N];
  long long vList[N];

  for ( int i=0; i<N; i++ ) {
    cin >> wList[i] >> vList[i];
  }

  long long wBase = LLONG_MAX;
  for ( int i=0; i<N; i++ ) {
    if ( wList[i] < wBase ) {
      wBase = wList[i];
    }
  }

  long long W_ = 305LL;
  for ( int i=0; i<N; i++ ) {
    wList[i] -= wBase;
  }
  
  long long dp[N+1][N+1][W_+1];
  for ( int n=0; n<N; n++ ) {
    for ( int k=0; k<N; k++ ) {
      for ( int w=0; w<=W_; w++ ) {

         dp[n][k][w]=0;

      }
    }
  }
  dp[0][0][0] = 0;
  for ( int n=0; n<N; n++ ) {
    for ( int k=0; k<N; k++ ) {
      for ( int w=0; w<=W_; w++ ) {

        if ( w-wList[n] >= 0 ) {
          dp[n+1][k+1][w] = max( dp[n][k][w-wList[n]] + vList[n], dp[n][k+1][w] );
        } else {
          dp[n+1][k+1][w] = dp[n][k+1][w];
        }

      }
    }
  }

  long long max_v = 0;
  for ( int k=0; k<=N; k++ ) {
    long long amari = W - k*wBase;
    if ( amari >= 0 ) {
      max_v = max( max_v, dp[N][k][min(amari, 300LL)] );
    }
  }
  cout << max_v << endl;

  return 0;
}

Measured memory_bytes: 24576
import java.util.*;

public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextLong() - (i + 1);
		}
		
		Arrays.sort(A);
		long b = A[N / 2];
		long ans = 0;
		for (int i = 0; i < N; i++) {
			ans += Math.abs(A[i] - b);
		}
		
		System.out.println(ans);
    }
}


Measured memory_bytes: 83712
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
#define inf 1e9


int main(){
	while(1){
		int n,k;
		cin>>n>>k;
		if(n==0) break;
		vector<int> dp(n+1,0);
		for(int i=0;i<k;i++){
			int tmp;
			cin>>tmp;
			dp[tmp] = 1;
		}
		int res = 0;
		for(int i=2;i<=n;i++){
			if(dp[i] == 1){
				dp[i] += dp[i-1];
				res = max(dp[i],res);
			}
		}
		/*for(int i=0;i<=n;i++){
			cout<<i<<' '<<dp[i]<<endl;
		}*/
		for(int i=n-1;i>=1;i--){
			if(dp[i] != 0 && dp[i+1] != 0){
				dp[i] = dp[i+1];
			}
		}
		if(dp[0] == 1){
			for(int i=2;i<n;i++){
				if(dp[i] == 0){
					res = max(res,dp[i-1]+dp[i+1] + 1);
					//cout<<i<<' '<<dp[i-1]<<' '<<dp[i+1]<<endl;
				}
			}
		}
		/*for(int i=0;i<=n;i++){
			cout<<i<<' '<<dp[i]<<endl;
		}*/
		cout<<res<<endl;
	}

	return 0;
}



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

int main(){

  vector<int> mt(10);

  for(int i=0;i<10;++i)
    cin>>mt[i];

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

  for(int i=9;i>=7;--i)
    cout<<mt[i]<<endl;
  
}



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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    int n, m;
    cin >> n >> m;
    int t1 = 1900*m+100*(n-m);
    double M = pow(0.5, m);
    cout << (ll)t1 / M << endl;
}

int main()
{
    solve();
    return 0;
}


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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007
//グリッドグラフの範囲チェック
bool range_validation(int y,int x,int h,int w){
    return y>=0 && y<h && x>=0 && x < w;
}
//ビットカウント
int popcount(long bits){
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int gcd(ll a, ll b){
  if(b == 0){
    return a;
  }else{
    return gcd(b,a%b);
  }
}

vector<ll> sieve(ll n){
  vector<bool> is_prime(n+1,true);
  vector<ll> res;
  for(int i=2;i<=n;i++){
    if(is_prime[i]){
      res.push_back(i);
      for(int j=2*i;j<=n;j+=i){
        is_prime[j] = false;
      }
    }
  }
  return res;
}

vector<ll> divisor(ll n){
  vector<ll> list;
  for(int i=2;i*i<=n;i++){
    if(n%i==0){
      list.push_back(i);
      if(n/i != i){
        list.push_back(n/i);
      }
    }
  }
  return list;
}

umap<int,int> prime_factor(ll n){
  umap<int,int> fac;
  for(int i=2;i*i<=n;i+=2){
    if(n%i == 0){
      int count = 0;
      while(n%i == 0){
        count++;
        n /= i;
      }
      fac[i] = count;
    }
  }
  if(n!=1)fac[n] = 1;
  return fac;
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  umap<ll,int> count;
  int n;
  cin >> n;
  int a[n];
  ll sum[n+1];
  sum[0] = 0;
  REP(i,n){
    cin >> a[i];
    sum[i+1] = sum[i] + a[i];
  }
  
  ll res = 0LL;
  
  REP(i,n+1){
    res += count[sum[i]];
    count[sum[i]]++;
  }
  
  cout << res << endl;
  
  return 0;
}


Measured memory_bytes: 13620
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using ull = long long unsigned;
using P = pair<int,int>;
const int MAX=1001001001;

P f(int x){
	int a,b;
	a=x%10;
	while (x>=10){
		x/=10;
	}
	b=x;
	return (make_pair(b,a));
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int h,n;
  cin>>h>>n;
	vector<P> p(n);

	rep(i,n){
		int a1,b1;
		cin>>a1>>b1;
		p[i]=make_pair(a1,b1);
	}
	vector<int> d(20005,MAX);
	d[0]=0;
	rep(i,h){
		rep(j,n){
			d[i+p[j].first]=min(d[i+p[j].first],d[i]+p[j].second);
		}
	}
int ans=MAX;
rep(i,10001){
	ans=min(ans,d[h+i]);
	//cout<<d[h+i]<<endl;
}
cout<<ans;




}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 1000000007
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a);
        a=(a*a);
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i));
        pro/=(i+1);
    }
    return pro;
}
int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k;
    cin>>n>>k;
    ll cnt=0;
    vector<ll > arr(n);
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(arr[i]>arr[j]) cnt++;
        }
    }
    if(k>1){
        cnt=(cnt*k)%mod;
        for(int i=0;i<n;i++){
            ll c=0;
            for(int j=0;j<n;j++){
                if(arr[i]>arr[j]){
                    c++;
                }
            }
            ll temp=((k*(k-1))/2ll)%mod;
            cnt=(cnt+(c*temp)%mod)%mod;
        }
        cout<<cnt;
      	return 0;
    }
  	cout<<cnt;
    return 0;
}


Measured memory_bytes: 256
import numpy as np
N, M = map(int, input().split())
A = np.array([[j for j in input()] for i in range(N)])
B = np.array([[j for j in input()] for i in range(M)])
ans = 'No'
for l in range(N-M+1):
    for d in range(N-M+1):
        if np.array_equal(A[l:l+M,d:d+M], B):
            ans = 'Yes'
print(ans)

Measured memory_bytes: 12432
/**
*    created: 14.05.2020 11:20:16
**/
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int mx = 0;
    int cnt = 0;
    rep(i,n) {
        mx = max(mx, h[i]);
        if (mx <= h[i]) cnt++;
    }
    cout << cnt << endl; 
    return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <ctype.h>

int main(int argc, char *argv[])
{
    char str[1201] = {};
    if (fgets(str, sizeof(str), stdin))
    {
        for (char *elm = str; *elm; ++elm)
        {
            const char c = isupper(*elm) ? tolower(*elm) : islower(*elm) ? toupper(*elm) : *elm;
            printf("%c", c);
        }
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  
  vector<ll> h(N);
  for (int i = 0; i < N; i++) {
    ll t;
    cin >> t;
    h[i] = t;
  }
  
  vector<ll> c(N);
  c[0] = 0;
  c[1] = abs(h[0] - h[1]);
  for (int i = 2; i < N; i++) {
    ll c1 = c[i-1] + abs(h[i-1] - h[i]);
    ll c2 = c[i-2] + abs(h[i-2] - h[i]);
    c[i] = min(c1, c2);
  }
  
  cout << c[N-1] << endl;
  
  return 0;
}

Measured memory_bytes: 1792
while 1:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break

    x = max(a, b)
    y = min(a, b)

    cnt = 0
    while 1:
        cnt += 1
        tmp = x % y
        x, y = y, tmp
        if tmp == 0:
            break

    print(x, cnt)


Measured memory_bytes: 5608
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
map<long long,long long> dp[65];
long long solve(long long n,int b)
{
	if (!n || b==-1)
	return 1;
	int m=60;
	while (!(n&(1LL<<m)))
	m--;
	b=min(b,m);
	if (dp[b].count(n))
	return dp[b][n];
	long long ans=solve((1LL<<m)-1,b);
	if (m<=b)
	ans=(ans+solve(n^(1LL<<m),m-1))%mod;
	if (m<=b+1)
	{
		for (int i=m-1;i>=0;i--)
		ans=(ans+solve(n^(1LL<<m),i-1))%mod;
	}
	return dp[b][n]=ans;
}
int main()
{
	long long n;
	scanf("%lld",&n);
	printf("%lld",solve(n,60));
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
using namespace std;

bool check(int i, int j){
    return i==0 || j==0;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    vector<vector<pair<int,pair<int,int>>>> dp(s.length()+1,vector<pair<int,pair<int,int>>>(t.length()+1,mp(0,mp(0,0))));
    for(int i=1 ; i<=s.length() ; i++){
        for(int j=1 ; j<=t.length() ; j++){
            if(s[i-1]==t[j-1]){
                dp[i][j]=mp(dp[i-1][j-1].first+1,mp(i-1,j-1));
            }else{
                if(dp[i][j-1].first>=dp[i-1][j].first){
                    dp[i][j]=mp(dp[i][j-1].first,mp(i,j-1));
                }else{
                    dp[i][j]=mp(dp[i-1][j].first,mp(i-1,j));
                }
            }
        }
    }
    //cout<<dp[s.length()][t.length()].first<<endl;
    
    string ans="";
    pair<int,int> curr=mp(s.length(),t.length());
    while(!check(curr.first,curr.second)){
        pair<int,int> prev = dp[curr.first][curr.second].second;
        if(prev.first+1==curr.first && prev.second+1==curr.second){
            ans+=s[curr.first-1];
        }
        curr=prev;
    }
    reverse(ans.begin(),ans.end());
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 105984
n, t_max = gets.chomp.split(" ").map(&:to_i)
  t = gets.chomp.split(" ").map(&:to_i)
  sum = 0
  (n-1).times do |i|
    if t_max > (t[i+1]-t[i])
      sum += (t[i+1]-t[i])
    elsif t_max <= (t[i+1]-t[i])
      sum += t_max
    end
  end
  sum += t_max
  puts sum

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

constexpr int INF = 1e9;
constexpr ll INFLL = 1e18;
constexpr int MOD = 1e9 + 7;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    //cout << fixed << setprecision(6);
    int n; cin >> n;
    vi d1(n), d2(n);
    rep (i, n) cin >> d1[i] >> d2[i];

    for (int i = 0; i < n-2; i++) {
        if (d1[i] == d2[i] and d1[i+1] == d2[i+1] && d1[i+2] == d2[i+2]) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

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

using i64 = int_fast64_t;
using f64 = double;

constexpr i64 INF = INT_FAST64_MAX / 2;
constexpr f64 EPS = DBL_EPSILON;

void solve() {
    i64 k, t;
    cin >> k >> t;

    i64 ans = 0;
    for (i64 i = 0; i < t; i++) {
        i64 a;
        cin >> a;
        if (a > (k + 1) / 2) ans = k - 2 * (k - a) - 1;
    }

    cout << ans << endl;
}

int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define in ({int x=0;int c=getchar(),n=0;for(;!isdigit(c);c=getchar()) n=(c=='-');for(;isdigit(c);c=getchar()) x=x*10+c-'0';n?-x:x;})
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l,int r){return l+rng()%(r-l+1);}
#define fasty ios_base::sync_with_stdio(false),cin.tie(nullptr);
#define task "random"
#define forinc(a,b,c) for(int a=b,_c=c;a<=_c;++a)
#define fordec(a,b,c) for(int a=b,_c=c;a>=_c;--a)
#define forv(a,b) for(auto&a:b)
#define fi first
#define se second
#define pb push_back
#define ii pair<int,int>
#define mt make_tuple
#define all(a) a.begin(),a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define bit(x,i) ((x>>(i-1))&1)
#define on(x,i) (x|(1ll<<(i-1)))
#define off(x,i) (x&~(1<<(i-1)))

const int N=3333;

int n,t,ret;
int a[N],b[N];
int f[N][N][2];

main(){
    //freopen(task".inp","r",stdin);
    //freopen(task".out","w",stdout);
    n=in,t=in;
    forinc(i,1,n) a[i]=in,b[i]=in;
    reset(f,-1);
    f[0][0][0]=0;
    forinc(i,0,n-1){
        forinc(j,0,t){
            forinc(k,0,1) if(f[i][j][k]>-1){
                if(!k) f[i+1][j][1]=max(f[i+1][j][1],f[i][j][k]+b[i+1]);
                if(j+a[i+1]<=t) f[i+1][j+a[i+1]][k]=max(f[i+1][j+b[i+1]][k],f[i][j][k]+b[i+1]);
                f[i+1][j][k]=max(f[i+1][j][k],f[i][j][k]);
            }
        }
    }
    forinc(j,0,t){
        forinc(k,0,1){
            if(k && j==t) continue;
            ret=max(ret,f[n][j][k]);
        }
    }
    cout<<ret;
}



Measured memory_bytes: 173824
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define intt int64_t
#define all(vec) vec.begin(), vec.end()

int main() {
    int n;
    scanf("%d", &n);
    vector<int> vec(n+1);
    rep(i,n) scanf("%d", &vec.at(i));
    vec.at(n) = 0;
    vector<int> dp(n+1);
    dp.at(0) = 0;
    rep(i,n) {
        if (i == 0) {dp.at(1) = 0; continue;}
        if (i == 1) {dp.at(2) = dp.at(1)+abs(vec.at(1)-vec.at(0)); continue;}
        dp.at(i+1) = min(
            dp.at(i)+abs(vec.at(i)-vec.at(i-1)),
            dp.at(i-1)+abs(vec.at(i)-vec.at(i-2))
            );
    }
    printf("%d\n", dp.at(n));
}

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

#define pan(i,n) for(int i=0;i<n;i++)
#define pans(i,n,a) for(int i=a;i<n;i++)
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define INF 1e9+7
#define PI 3.141592653
#define inf 100007
#define P pair<ll,ll>

using namespace std; 

int main(){
    int r;
    cin>>r;
    double ans=2*PI*r;
    cout<<ans;
}

Measured memory_bytes: 3788
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <bitset>

long long mod = 1e9+7;
class Mint {
public:
  long long x;
  Mint(){}; // 引数なしでも定義できるように引数なしコンストラクタも用意しておく
  Mint(long long a){
    x = a%mod;
    while(x<0){
      x += mod;
    }
  };
  Mint& operator += (const Mint &a){
    x+=a.x;
    x%=mod;
    return *this;
  }
  Mint& operator -= (const Mint &a){
    x += (mod - a.x);
    x%=mod;
    return *this;
  }
  Mint& operator *= (const Mint &a){
    x*=a.x;
    x%=mod;
    return *this;
  }

  // a^n mod を計算する
  // Useaeg: Mint z = y.pow(y, n);
  Mint pow(Mint a, long long n) const {
    Mint y(1);
    Mint b(a);
    while (n > 0) {
      if (n & 1) y *= b;
      b *= b;
      n >>= 1;
    }
    return y;
  }

  // a^{-1} mod を計算する
  Mint modinv(const Mint &a) const {
    return pow(a, mod-2);
  }

  Mint& operator /= (const Mint &a) {
    x *= modinv(a).x;
    x %= mod;
    return *this;
  }

  Mint operator + (Mint &a) const {
    Mint y(*this);
    y += a;
    return y;
  }

  Mint operator - (Mint &a) const {
    Mint y(*this);
    y -= a;
    return y;
  }

  Mint operator * (Mint &a) const {
    Mint y(*this);
    y *= a;
    return y;
  }

  Mint operator / (Mint &a) const {
    Mint y(*this);
    y/=a;
    return y.x;
  }

  // nCk @mod を計算する
  Mint nCk(Mint &n, const long long k) const {
    Mint y = Mint(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
      y /= i;
    }
    return y;
  }

  // nPk @mod を計算する
  Mint nPk(Mint &n, long long k) const {
    Mint y(1);
    for (Mint i(0); (i.x)<k; i.x++){
      y *= (n-i);
    }
    return y;
  }
};

struct node {
  int v;
  int supply;
  int amari;
};

class MyComparison {
public:
  bool operator()(node n1, node n2) {
    return (n1.supply!=n2.supply)?(n1.supply>n2.supply):(n1.amari<n2.amari);
  }
};

int main() {
  int N;
  std::cin >> N;
  std::vector<int > L(N);
  for (int i=0; i<N; i++) {
    std::cin >> L[i];
  }
  std::sort(L.begin(), L.end());
  int ans = 0;
  for (int i=0; i<N; i++){
    for (int j=i+1; j<N; j++) {
      for (int k=j+1; k<N; k++) {
        if (L[i]==L[j] || L[j]==L[k]) continue;
        if (L[i]+L[j]>L[k]) ans++;
      }
    }
  }
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
  string str;
  cin>>str;
  ll ans=0;;
  vector<ll> rightsearch((ll)str.size()+1);
  vector<ll> leftsearch((ll)str.size()+1);
  rightsearch.at((ll)str.size())=0;
  for(ll i=0;i<(ll)str.size();i++){//右側の>探索
    if(str.at((ll)str.size()-1-i)=='>'){rightsearch.at((ll)str.size()-1-i)=rightsearch.at((ll)str.size()-i)+1;}
  }
  leftsearch.at(0)=0;
  for(ll i=1;i<=(ll)str.size();i++){//左側の<探索
    if(str.at(i-1)=='<'){leftsearch.at(i)=leftsearch.at(i-1)+1;}
  }
  for(ll i=0;i<=(ll)str.size();i++){
    ans+=max(rightsearch.at(i),leftsearch.at(i));
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 8708
import sys
sys.setrecursionlimit(10**6)

n = int(input())
#b = list(map(int, input().split()))
#n, m = map(int, input().split())
#s = input()
#s,t = input().split()
#a = [int(input()) for _ in range(n)]
#
#readline = sys.stdin.readline
#n,m = [int(i) for i in readline().split()]
#ab = [[int(i) for i in readline().split()] for _ in range(n)]

import math

ans = [0]*(n+1)
upper = math.ceil(math.sqrt(n))

for x in range(1,upper+1):
    for y in range(1,upper+1):
        for z in range(1,upper+1):
            tmp = pow((x+y),2)+pow((y+z),2)+pow((x+z),2)
            if tmp%2 == 0 and tmp//2 <= n:
                ans[tmp//2] += 1
                
print(*ans[1:])

Measured memory_bytes: 9340
S=input()
T=input()

Alpha= [[0 for i in range(1)] for j in range(26)]
Beta= [[0 for i in range(1)] for j in range(26)]

for i in range(len(S)):
  Alpha[ord(S[i])-97].append(T[i])
  Beta[ord(T[i])-97].append(S[i])

for i in range(26):
  Alpha[i]=list(set(Alpha[i]))
  Beta[i]=list(set(Beta[i]))
  if len(Alpha[i])>=3 or len(Beta[i])>=3:
    print('No')
    exit()
print('Yes')

Measured memory_bytes: 7984
# INPUT
# 普通の入力
s = input()
t = input()

# PROCESS
def round(s_local):
  s_list = list(s_local)
  last_letter = s_list.pop(0)
  s_list.append(last_letter)
  return "".join(s_list)

answer = "No" 
for i in range(len(s)):
  s = round(s)
  if (s == t):
    answer = "Yes"
    break


# OUTPUT
print(answer)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <map>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()

#define pci pair<char,int>
int main() {
  map<char,int> hoge;
  hoge.insert(pci('I',1));
  hoge.insert(pci('V',5));
  hoge.insert(pci('X',10));
  hoge.insert(pci('L',50));
  hoge.insert(pci('C',100));
  hoge.insert(pci('D',500));
  hoge.insert(pci('M',1000));

  string s;
  while(cin >> s) {
    vector<int> v;
    REP(i,s.length()) {
      v.push_back((*hoge.find(s[i])).second);
    }
    int ans = 0;
    REP(i,v.size()) {
      if (i<v.size()-1 && v[i]<v[i+1])
        ans -= v[i];
      else
        ans += v[i];
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

#define ABS(x) ( (x)>0 ? x : -(x) )
#define MIN(x,y) ( (x) < (y) ? (x) : (y) )
#define MAX(x,y) ( (x) > (y) ? (x) : (y) )

#define MOD 1000000007

void swap(int* a, int* b)
{
	int tmp;
	tmp = *a;
	*a = *b;
	*b = tmp;
}

void print(int A[], int n)
{
	int i;
	for (i = 0; i < n; i++)
	{
		printf("%d", A[i]);
		if (i != n - 1)
			printf(" ");
	}
	printf("\n");
}

void insertionSort(int A[], int N)
{
	int i, j,tmp;

	for (i = 1; i < N; i++)
	{
		j = i;
		while (j > 0 && A[j - 1] > A[j])
		{
			tmp = A[j - 1];
			A[j - 1] = A[j];
			A[j] = tmp;

			j--;
		}
		print(A, N);
	}
}

void bubbleSort(int A[], int N,int *count)
{
	int flag = 0;
	int i, j,tmp;

	for (i = 0; i < N; i++)
	{
		for (j = N - 1; j > 0; j--)
		{
			if (A[j - 1] > A[j])
			{
				tmp = A[j - 1];
				A[j - 1] = A[j];
				A[j] = tmp;
				flag = 1;
				(*count)++;
			}
		}
		if (flag == 0)
			break;
		else
			flag = 0;
	}
}

void selectionSort(int A[], int N,int *count)
{
	int i, j;
	int key,tmp;

	for (i = 0; i < N; i++)
	{
		key = i;
		for (j = i; j < N; j++)
		{
			if (A[j] < A[key])
				key = j;
		}
		if (i != key)
		{
			tmp = A[i];
			A[i] = A[key];
			A[key] = tmp;
			(*count)++;
		}
	}
}

int main()
{
	int A[10000];
	int N, i;

	int count = 0;

	scanf("%d", &N);

	for (i = 0; i < N; i++)
		scanf("%d", &A[i]);

	//print(A, N);

	selectionSort(A, N,&count);

	print(A, N);

	printf("%d\n", count);

	return 0;
}


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

using namespace std;

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

    int last = 0;
    bool possible = true;
    for (int i = 0; i < n; ++i) {
        int h;
        cin >> h;
        if (h > last) {
            last = h - 1;
        } else if (h == last) {
            last = h;
        } else {
            possible = false;
            break;
        }
    }

    cout << (possible ? "Yes" : "No") << endl;

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
	int A, B, x, y, z;
	scanf("%d %d", &A, &B);

	x = A + B;
	y = A - B;
	z = A * B;

	if(x >= y) {
		if(x >= z) {
			printf("%d\n", x);
		} else {
			printf("%d\n", z);
		}
	} else if(y >= z) {
		printf("%d\n", y);
	} else {
		printf("%d\n", z);
	}
	return 0;
}

Measured memory_bytes: 128
// https://atcoder.jp/contests/abc131/tasks/abc131_f

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

//------------------------------------------------------------------------------
const int V_MAX = 1e5;

vector<int> G[V_MAX];

void add_edge(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}

//------------------------------------------------------------------------------
const int N_MAX = 1e5;
const int X_I_MAX = 1e5;
const int Y_I_MAX = 1e5;

struct P { int id, x, y; };
int N;
P ps[N_MAX];

bool used[V_MAX];
ll cnt;
set<int> xst;
set<int> yst;

bool compare_x_asc_y_asc(const P& p1, const P& p2) {
  if (p1.x != p2.x) return p1.x < p2.x;
  return p1.y < p2.y;
}

bool compare_y_asc_x_asc(const P& p1, const P& p2) {
  if (p1.y != p2.y) return p1.y < p2.y;
  return p1.x < p2.x;
}

bool compare_id_asc(const P& p1, const P& p2) {
  return p1.id < p2.id;
}

void dfs2(int p, int v) {
  used[v] = true;
  cnt++;
  xst.insert(ps[v].x);
  yst.insert(ps[v].y);
  for (int u : G[v]) {
    if (u == p) continue;
    if (used[u]) continue;
    dfs2(v, u);
  }
}

ll dfs(int v) {
  cnt = 0;
  xst.clear();
  yst.clear();
  dfs2(-1, v);
  if (xst.size() > 1 && yst.size() > 1) {
    return (ll) xst.size() * (ll) yst.size() - cnt;
  } else {
    return 0;
  }
}

void solve() {
  sort(ps, ps + N, compare_x_asc_y_asc);
  REP(i, N - 1) if (ps[i].x == ps[i + 1].x) add_edge(ps[i].id, ps[i + 1].id);
  sort(ps, ps + N, compare_y_asc_x_asc);
  REP(i, N - 1) if (ps[i].y == ps[i + 1].y) add_edge(ps[i].id, ps[i + 1].id);
  sort(ps, ps + N, compare_id_asc);

  ll ans = 0;
  REP(v, N) {
    if (used[v]) continue;
    ans += dfs(v);
  }
  printf("%lld\n", ans);
}

void input() {
  scanf("%d", &N);
  REP(i, N) {
    int x, y;
    scanf("%d%d", &x, &y);
    ps[i] = { i, x, y };
  }
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 16256
#include<bits/stdc++.h>
using namespace std;
int DP[30100];
int A[1010],B[1010];
int main()
{
  for(int i=1;i<30100;i++)
    DP[i]=987987987;
  int H,N;
  cin>>H>>N;
  for(int i=0;i<N;i++)
    cin>>A[i]>>B[i];
  for(int i=0;i<=H;i++)
    for(int j=0;j<N;j++)
      DP[i+A[j]]=min(DP[i+A[j]],DP[i]+B[j]);
  sort(DP+H,DP+30099);
  cout<<DP[H]<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int main() {
    int N;
    cin >> N;
    int C[510], S[510], F[510];
    for (int i=1; i<N; i++){
        cin >> C[i] >> S[i] >> F[i];
    }

    int ans[510];

    for (int i=1; i<N; i++){
        ans[i] = S[i];
        for (int j=i; j<N; j++){
            ans[i] = max((ans[i] + F[j] - 1)/F[j] * F[j], S[j]) + C[j];
        }
    }
    ans[N] = 0;

    for (int i=1; i<=N; i++) {
        cout << ans[i] << endl;
    }

}


Measured memory_bytes: 256
from heapq import *
import sys
from collections import *
from itertools import *
from decimal import *
import copy
from bisect import *
import time
import math
sys.setrecursionlimit(4100000)
def gcd(a,b):
    if(a%b==0):return(b)
    return (gcd(b,a%b))
N,M,S=map(int,input().split())
UVAB=[list(map(int,input().split())) for i in range(M)]
CD=[[0,0]]+[list(map(int,input().split())) for i in range(N)]
data=[defaultdict(list) for i in range(N+1)]

for u,v,a,b in UVAB:
    data[u][v]=[a,b]
    data[v][u]=[a,b]
idel_max=10**18
visited=[[idel_max for i in range(2501)] for n in range(N+1)]
visited2=[[0 for i in range(2501)] for n in range(N+1)]
stack=[]
t=0
c,d=CD[1]
flag=0
s=min(S,2500)
"""while not flag:
    if s>2500:
        s=2500
        flag=1
    visited[1][s]=t
    stack.append([t,s,1])
    t+=d
    s+=c"""

stack=[[t,s,1]]
visited[1][s]=t
while stack:
    #print(len(stack))
    #print(stack[-1])
    #print(stack[0])
    t,s,q=heappop(stack)
    c,d=CD[q]
    flag=0
    if not visited2[q][s]:
        visited2[q][s]=1
        if s<2500:
            _s=min(s+c,2500)
            _t=t+d

            if _t<visited[q][_s]:
                #print("a")
                visited[q][_s]=_t
                heappush(stack,[_t,_s,q])

        for p in data[q]:
            a,b=data[q][p]
            _s=s-a
            if _s>=0:
                _t=t+b
                if _t<visited[p][_s]:
                    visited[p][_s]=_t
                    heappush(stack,[_t,_s,p])
#print(visited[1])
for i in range(2,N+1):
    print(min(visited[i]))


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

int main()
{
    int h, w;

    while ((cin >> h >> w), h != 0 || w != 0) {
        for (int y = 0; y < h; ++y) {
            for (int x = 0; x < w; ++x) {
                cout << "#."[(x + y) % 2];
            }

            cout << endl;
        }

        cout << endl;
    }


    return 0;
}

Measured memory_bytes: 1152