akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main()
{
  int i, j, a[100], v, n;
  
  scanf("%d",&n);
  
  for(i = 0; i < n; i++)
    {
      scanf("%d",&a[i]);
    }
  
  for(i = 0; i < n; i++)
    {
      v = a[i];
      j = i - 1;
      
      while(j >= 0 && a[j] > v)
	{
	  a[j+1] = a[j];
	  j--;
	}
      
      a[j+1] = v;
      
      for(v = 0; v < n-1; v++)
	{
	  printf("%d ",a[v]);
	}
      printf("%d\n",a[v]);
    }  

  return 0;
}



Measured memory_bytes: 2048
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

N = input()
t_, x_, y_ = 0, 0, 0
flag = True
for i in range(N):
    t, x, y = map(int, raw_input().split())
    if t - t_ < abs(x - x_) + abs(y - y_) or (x + y + t + x_ + y_ + t_) % 2:
        flag = False
    t_, x_, y_ = t, x, y

print "Yes" if flag else "No"

Measured memory_bytes: 6008
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	int i, j, c;
	char s[1001], t[6]="apple", u[6]="peach", r[1001], x[6];
	bool f = false;
	cin.getline(s, sizeof(s));
	i = 0;
	while (1)
	{
		if (!f)
			c = 0;
		switch (s[i+c])
		{
		case 'a':
			if (c == 0 || c == 2)
			{
				f = true;
				x[c] = 'a';
				c++;
			}
			else
			{
				r[i] = s[i];
				i++;
			}
			break;
		case 'p':
			if (0 <= c && c <= 2)
			{
				f = true;
				x[c] = 'p';
				c++;
			}
			else
			{
				r[i] = s[i];
				i++;
			}
			break;
		case 'l':
			if (c == 3)
			{
				f = true;
				x[c] = 'l';
				c++;
			}
			else
			{
				r[i] = s[i];
				i++;
			}
			break;
		case 'e':
			if (c == 1 || c == 4)
			{
				f = true;
				x[c] = 'e';
				c++;
			}
			else
			{
				r[i] = s[i];
				i++;
			}
			break;
		case 'c':
			if (c == 3)
			{
				f = true;
				x[c] = 'c';
				c++;
			}
			else
			{
				r[i] = s[i];
				i++;
			}
			break;
		case 'h':
			if (c == 4)
			{
				f = true;
				x[c] = 'h';
				c++;
			}
			else
			{
				r[i] = s[i];
				i++;
			}
			break;
		default:
			r[i] = s[i];
			i++;
		}
		if (c >= 5)
		{
			x[c] = '\0';
			if (strcmp(x, t) == 0)
				for (j = 0; j < 5; j++, i++)
					r[i] = u[j];
			if (strcmp(x, u) == 0)
				for (j = 0; j < 5; j++, i++)
					r[i] = t[j];
			f = false;
		}
		if (i >= strlen(s))
			break;
	}
	r[strlen(s)] = '\0';
	cout << r << endl;
}

Measured memory_bytes: 0
import collections
N,M =map(int,input().split())
A = [0] + list(map(int,input().split()))
for i in range(N):
  A[i+1] = (A[i]+A[i+1])%M
ans = 0
c = collections.Counter(A)
for a in set(A):
  n = c[a]
  ans += int(n*(n-1)/2)
print(ans)

Measured memory_bytes: 15004
h,w,k = gets.split.map(&:to_i)
c = h.times.map{gets.split('').map{|c|c=='#'}}

ans = 0
(2**(h+w)).times{|i|
  s = 2**(h+w)+i
  s = s.to_s(2)[1..-1]
  #p s
  cnt = 0
  h.times{|j|
    w.times{|k|
      if s[j]!='0' && s[h+k]!='0'
        if c[j][k]
          cnt += 1
        end
      end
    }
  }
  #p cnt
  ans += 1 if cnt==k
}

p ans


Measured memory_bytes: 14368
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		int K = I.nextInt();
		int ans = N;
		boolean[] bad = new boolean[10];
		for (int i = 0; i < K; i++) {
			int x = I.nextInt();
			bad[x]=true;
		}
		for (int i = N;;i++) {
			int cur = i;
			boolean good=true;
			while (cur>0) {
				int dig = cur%10;
				if (bad[dig]) {
					good=false;
					break;
				}
				cur/=10;
			}
			if (good) {
				ans=i;
				break;
			}
		}
		O.pln(ans);
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


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

using namespace std;
typedef long long ll;
int main() {
  int n;
  cin >> n;
  vector<int> f(n + 1, 2);
  f[1] = 1;
  ll ans = 1;
  for (int i = 2; i <= n; ++i) {
    ans += (ll)i * f[i];
    for (int j = 2 * i; j <= n; j += i)
      f[j]++;
  }
  cout << ans;
}

Measured memory_bytes: 42336
import sys
s = sys.stdin.readlines()

N,M,Q = map(int,s[0].split())

Section = [[0]*N for _ in [0]*N]
for L,R in (map(int, e.split()) for e in s[1:M+1]):
    Section[L-1][R-1] += 1

Sum = [[0]*(N+1) for _ in [0]*(N+1)]
for i in range(N):
    for j in range(N):
        Sum[i+1][j+1] = Sum[i][j+1]+Sum[i+1][j]-Sum[i][j]+Section[i][j]

for p,q in (map(int, e.split()) for e in s[M+1:]):
    print(Sum[q][q]-Sum[p-1][q])

Measured memory_bytes: 36872
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::cmp::{min,max};

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn read<T: FromStr>() -> T {
    let cin = stdin();
    let cin = cin.lock();
    let s: String = cin 
        .bytes() // Bytes
        .map(|c| c.expect("failed reading char") as char)
        .skip_while(|c| c.is_whitespace()) // c が whitespace である限り skip
        .take_while(|c| !c.is_whitespace()) // c が whitespace でない限り要素を返す
        .collect();
    s.parse().ok().expect("failed parsing")
}

fn main() {
    input! {
        x : usize,
        y : usize
    }
    println!("{}", x + y / 2);
}


Measured memory_bytes: 4352
<?php
// Your code here!
    $num = array_map('floatval',explode(" ",trim(fgets(STDIN))));

    $height = $num[1]*sin(deg2rad($num[2]));
    
    $sq = $num[0]*0.5*$height;

    $c = sqrt(pow($num[0],2)+pow($num[1],2)-2*$num[0]*$num[1]*cos(deg2rad($num[2])));

    echo $sq."\n";
    echo $c+$num[0]+$num[1]."\n";
    echo $height."\n";
?>



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

int main() {
  int N, A;
  cin >> N;
  A=N%10;
  if(A==1 || A==6 || A==8 || A==0) cout << "pon" << endl;
  else if(A==2 || A==4 || A==5 || A==7 || A==9 ) cout << "hon" << endl;
  else cout << "bon" << endl;
}

Measured memory_bytes: 3624
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int m = scan.nextInt();
    int c = 0;
    int d = 0;
    boolean [] a = new boolean[n];
    int [] t = new int[n];

    for (int p=0;p<n;p++){
      a[p] = false;
      t[p] = 0;
    }

    for (int i=0;i<m;i++){
      int g = scan.nextInt();
      String check = scan.next();

      if (a[g-1] == true){
        continue;
      }

      if (check.equals("AC") == true){
        c += 1;
        a[g-1] = true;
        d += t[g-1];
      }
      else{
        t[g-1] += 1;
      }
    }

    System.out.print(c+" ");
    System.out.println(d);
  }
}


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

int main() {
	int h, w; cin >> h >> w;
	map<char, int>ct;
	for (int i = 0; i < h * w; i++) {
		char x;
		cin >> x;
		if (ct.count(x))ct.at(x)++;
		else ct[x] = 1;
	}
	ll m4 = 0; ll m2 = 0; ll m1 = 0;
	for (auto a : ct) {
		int x = a.second;
		m4 += x / 4;
		x -= (x / 4) * 4;
		m2 += x / 2;
		x -= (x / 2) * 2;
		m1 += x;
	}
	if (h % 2 == 1 && w % 2 == 1) {
		if (m4 >= ((h - 1) / 2) * ((w - 1) / 2)) {
			m2 += (m4 - ((h - 1) / 2) * ((w - 1) / 2)) * 2;
			if (m2 >= (h - 1) / 2 + (w - 1) / 2) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
	else if (h % 2 == 0 && w % 2 == 0) {
		if (m4 >= (h / 2) * (w / 2))cout << "Yes" << endl;
		else cout << "No" << endl;
	}
	else {
		if (h % 2 == 1)swap(h, w);
		if (m4 >= (w - 1) * h / 4) {
			m2 += (m4 - (w - 1) * h / 4) * 2;
			if (m2 >= h / 2) cout << "Yes" << endl;
			else cout << "No" << endl;
		}
		else cout << "No" << endl;
	}
}

Measured memory_bytes: 256
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces1249B
import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static java.lang.Math.*;
import java.math.*;

public class Main{

	static PrintWriter go = new PrintWriter(System.out);
	
	public static void main(String args[]) throws IOException,FileNotFoundException {
		BufferedReader gi = new BufferedReader(new InputStreamReader(System.in, "ISO-8859-1"));
		int n = Integer.parseInt(gi.readLine());
		int ans = n / 2 - 1 + n % 2;
		go.println(ans);
		go.close();
	}

	static int[] parseArray(BufferedReader gi) throws IOException{
		String[] line = gi.readLine().split(" ");
		int[] rez = new int[line.length];
		for ( int k = 0; k < line.length; k++){
			rez[k] =  Integer.parseInt(line[k]);
		}
		return rez;
	}

}

Measured memory_bytes: 21204
x = 0
while true
  n = gets.to_i
  if n == 0
    break
  end
  min = 1000
  max = 0
  sum = 0
  n.times{
    s = gets.to_i
    sum += s
    if s < min
      min = s
    end
    if max < s
      max = s
    end
  }
  puts (sum - min - max) / (n - 2)
end

Measured memory_bytes: 8756
#include <iostream>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <map>
#include <deque>
#include <cmath>
#include <vector>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>

// short keywords

#define ipow(a,b) (ll)pow(a,b)
#define pi(a,b) pair<ll,ll>(a,b)
#define pis(a,b) pair<ll,string>(a,b)
#define pc(c,d) pair<ll,pair<ll,string>>(c,d)
#define pp(a,b,c) pair<pair<ll,ll>,ll>(pi(a,b),c)
#define ps(a,b,c) pair<string,pair<ll,ll>>(a,pi(b,c))

// for loops

#define rep(i,n) for(ll i=0;i<n;i++)
#define reps(i,a,b) for(ll i=a;i<=b;i++)
#define rev(i,a,b) for(ll i=a;i>=b;i--)
#define mod 1000000007
using namespace std;

// short keywords2
typedef long long ll;
typedef set<ll>::iterator sit;
typedef vector <ll> ::iterator vit;
typedef map<ll,ll>::iterator mit;
typedef multimap<ll,ll>::iterator mmit;

class Task
{
public:
    void solve(istream& in,ostream& out)
    {
        set<ll>check;
        int n;
        in>>n;
        char a[n];

        rep(i,n)
        {
            in>>a[i];
        }

        int x=0;
        check.insert(x);
        rep(i,n)
        {
            if(a[i]=='I')
            {
                x++;
                check.insert((ll)x);
            }
            else if(a[i]=='D')
            {
                x--;
                check.insert((ll)x);
            }
        }

        out<<*check.rbegin()<<endl;
    }

    ll c(ll a,ll b)
    {
        ll res=0;
        reps(i,1,15)
        {
            if(a/(ll)pow(b,i)!=0)
            {
                res+=a/(ll)pow(b,i);
            }
            else
            break;
        }

        return res;
    }

    bool isprime(ll n)
    {
        if(n==1 || (n%2==0 && n!=2))
        {
            return false;
        }
        else if(n==2 || n==3)
        {
            return true;
        }
        else
        {
            ll res=0;
            for(ll i=3 ;i<=(ll)sqrt(n) ;i+=2)
            {
                if(n%i==0)
                {
                    res++;
                    break;
                }
            }

            if(res==0)
            {
                return true;
            }
            else
            return false;
        }
    }
};


int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	Task solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in,out);
	out.flush();

    return 0;
}


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

main(){
  int i,n,m,v[110];
  while(scanf("%d%d",&n,&m),n+m){
    int a[110]={0},h=0,w=0;
    for(i=0;i<n;i++){
      scanf("%d",&v[i]);
      h = max(h,++a[v[i]/m]);
      w = max(w,v[i]/m);
    }
    double res = 0.01;
    for(i=0;i<w;i++)res += (double)a[i]/h * (double)(w-i)/w;
    printf("%.9lf\n",res);
  }
}

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

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ldb;

#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define all(v) (v).begin(), (v).end()
#define dbg(a) cerr << #a << " = " << a << endl

int main() {

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

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int a, b;
    cin >> a >> b;
    if((a * b) % 2 == 0) {
        cout << "Even";
    } else {
        cout << "Odd";
    }

    return 0;
}

Measured memory_bytes: 256
import itertools

N = int(input())
P = tuple(map(int, input().split()))
Q = tuple(map(int, input().split()))

PP = tuple(P)

A = list(itertools.permutations(range(1,N+1)))
PW = (A.index(P))
QW = (A.index(Q))

print(abs(PW-QW))


Measured memory_bytes: 8052
#include <bits/stdc++.h>
 
using namespace std;
 
#define int 		long long
#define endl		"\n"
#define mod			1000000007
#define IOS			ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
 
int32_t main(){
 
	IOS;
	
	int n;
	cin >> n;
	vector<int> h(n), dp(n);

	for(int i = 0; i < n; i++)
		cin >> h[i];

	dp[0] = 0, dp[1] = labs(h[1] - h[0]);

	for(int i = 2; i < n; i++)
		dp[i] = min(labs(h[i] - h[i-1]) + dp[i-1], labs(h[i] - h[i-2]) + dp[i-2]);
 	
 	cout << dp[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
 
using namespace std;
 
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
 
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


const int INF = 1e9;

double EPS = 1e-10;

int d[1010][1010];
pii dp[1010][1010];

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

vector<pii> p(1000010);

bool isPrime[1000010];

void setPrime(){
	for(int i = 2; i <= 1000000; i++){
		isPrime[i]=true;
	}
	for(int i = 2; i <= 1000000; i++){
		if(isPrime[i]==true){
			for(int j = i + i; j <= 1000000; j+=i){
				isPrime[j] = false;
			}	
		}
	}
}

int main(){
	setPrime();
	int n, m;
	while(cin>>m>>n){
		if(n == 0 && m == 0) break;

		for(int i = 0; i < 1010; i++){
			for(int j = 0; j < 1010; j++){
				dp[i][j].fi=dp[i][j].se=d[i][j]=0;
			}
		}
		for(int i = 0; i<=1000000; i++){
			p[i]=mp(0,0);
		}
		int dir = 0;
		int x = 505, y = 505, nx, ny;
		for(int i = 1; i <= m; i++){
			nx = x+dx[dir]; ny = y+dy[dir];
			if(d[ny][nx]==0) {
				d[ny][nx] = i;
				p[i]=mp(nx, ny);
				dir++; dir%=4;
				x=nx; y=ny;
			}
			else{
				dir+=3;
				dir%=4;
				nx = x+dx[dir]; ny = y+dy[dir];
				d[ny][nx] = i;
				p[i]=mp(nx, ny);
				dir++; dir%=4;
				x=nx; y=ny;
			}
		}
		// for(int i = 500; i<=510; i++){
		// 	for(int j = 500; j <= 510; j++){
		// 		printf("%4d", d[i][j]);
		// 	}
		// 	cout<<endl;
		// }
		pii pp;
		for(int i = 1008; i>=0; i--){
			for(int j = 1009; j>=0; j--){
				if(isPrime[d[j][i]]) {
					dp[j][i] = max(dp[j][i], mp(1, d[j][i]));
				}
				for(int k=-1; k<=1; k++){
					if(j+k>=0 && j+k<1010){
						pp = dp[j+k][i+1];
						if(isPrime[d[j][i]]) pp.fi++;
						dp[j][i]=max(dp[j][i], pp);
					}
				}
			}
		}
		printf("%d %d\n", dp[p[n].se][p[n].fi].fi, dp[p[n].se][p[n].fi].se);
		
	}

}

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

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  vector<string> day{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
  for (int i = 0; i < 7; i++) {
    if (s == day[i])
      cout << 7 - i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		solve();
	}

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

		while(true){
			List<Integer> list=new ArrayList<Integer>();
			int n=sc.nextInt();
			int r=sc.nextInt();
			if(n+r==0)break;
			for(int i=n; i>=1; i--)
				list.add(i);

			for(int i=0; i<r; i++){
				List<Integer> stock=new ArrayList<Integer>();
				int p=sc.nextInt();
				int c=sc.nextInt();
				for(int j=c-1; j>=0; j--)
					stock.add(list.remove(p-1));
				for(int j=stock.size()-1; j>=0; j--)
					list.add(0,stock.get(j));

			}

			System.out.println(list.get(0));
		}
	}
}

Measured memory_bytes: 31220
def solve(a, k):
    cycle = []
    visited = set()
    curr = 0
    while curr not in visited:
        visited.add(curr)
        cycle.append(curr)
        curr = a[curr]
    if k < len(visited):
        return cycle[k]
    cycle_start = cycle.index(curr)
    k -= cycle_start
    cycle = cycle[cycle_start:]
    return cycle[k % len(cycle)]


if __name__ == "__main__":
    n, k = map(int, input().split())
    a = [int(x) - 1 for x in input().split()]
    print(solve(a, k) + 1)


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

#define INF 999999
#define MAX_M 20
#define MAX_PAY 50000

int min(int, int);

int main(){

    /* 変数定義 */
    int payment;                // 支払金額
    int m;                      // コインの種類数
    int coin[MAX_M];            // コインの額面
    int cost[MAX_PAY+1];   // 使用する最小のコイン枚数
    int i, j;

    /* 入力 */
    scanf("%d %d", &payment, &m);
    
    /*
    coin = (int *)malloc(m * sizeof(int));
    cost = (int **)malloc(m * sizeof(int *));
    for(i = 0; i <= payment; i++){
        cost[i] = (int *)malloc((payment + 1) * sizeof(int));
    }
    */

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

    /* 初期化 */
    cost[0] = 0;
    for(j = 1; j <= payment; j++){
       cost[j] = INF;
    }

    /* 動的計画法で問題を解く */
    /* cost[i][j] = i番目までのコインを使って、金額jを払うのに使用するコインの最小枚数 */
    for(i = 0; i < m; i++){
        for(j = coin[i]; j <= payment; j++){
            cost[j] = min(cost[j], cost[j - coin[i]] + 1);
        }
    }

    /* 出力 */
    /*
    for(j = 0; j <= payment; j++){
        printf("%d ", cost[j]);
    }
    printf("\n");
    */
    
    printf("%d\n", cost[payment]);

    return 0;
}

int min(int x, int y){
    int ans;
    
    ans = x < y ? x : y;

    return ans;
}


Measured memory_bytes: 2104
N=input()

for i in range(2):
    for j in range(2):
        for k in range(2):
            if int(N[0])+(-1)**i*int(N[1])+(-1)**j*int(N[2])+(-1)**k*int(N[3])==7:
                X=str(i)+str(j)+str(k)

Z=X.replace("0","+")
Z=Z.replace("1","-")

print(N[0]+Z[0]+N[1]+Z[1]+N[2]+Z[2]+N[3]+"=7")

Measured memory_bytes: 3064
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    LL A,B,C;
    GLL(A);GLL(B);GLL(C);
    printf("%lld\n", min(A+B+1, C) + B);
    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int N,L;
int ans=0;
int mod=1000000007;
signed main(){
    scanf("%lld %lld",&N,&L);
    ans=(int)(L+L+N-1)*N/2;
    if(L>0)ans-=L;
    if(L<0&&L+N-1<0)ans-=L+N-1;
    printf("%lld\n",ans);
}

Measured memory_bytes: 128
package main

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

var sc = bufio.NewScanner(os.Stdin)
var rd = bufio.NewReaderSize(os.Stdin, 10000000)

func readLine() string {
  buf := make([]byte, 0, 10000000)
  for {
	l, p, _ := rd.ReadLine()
	buf = append(buf, l...)
	if !p {
	  break
	}
  }
  return string(buf)
}

func nextStr() string {
  sc.Scan()
  return sc.Text()
}

func nextInt() int {
  sc.Scan()
  i, _ := strconv.Atoi(sc.Text())
  return i
}

func main() {
  sc.Split(bufio.ScanWords)
  N := nextInt()
  a := make([]int, 1)
  for i := 0; i < N; i += 1 {
    x := nextInt()
    a = append(a, x)
  }
  cnt := 0
  for i := 1; i <= N; i += 1 {
    if i % 2 != 0 && a[i] % 2 != 0 {
      cnt++
	}
  }
  fmt.Println(cnt)
}


Measured memory_bytes: 2188
#include <cstdio>

#define int long long

int N;
int A[200000];

signed main()
{
    scanf("%lld", &N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &A[i]);
    }

    int B_all = 0;
    int B;

    for (int i = 0; i < N; i++) {
        B_all += A[i];
    }

    int B_1 = B_all;
    for (int i = 1; i < N; i += 2) {
        B_1 -= A[i] * 2;
    }

    printf("%lld ", B_1);

    B = B_1;

    for (int i = 0; i < N - 2; i++) {
        B = 2 * A[i] - B;
        printf("%lld ", B);
    }
    B = 2 * A[N - 2] - B;
    printf("%lld\n", B);

    return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  ll N;
  ll ans=0;
  cin>>N;
  for(ll i=1;i<=N;i++){
    ans+=i*(N/i)*(N/i+1)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3608
#include <cmath>
#include <iostream>
#include <string>
#include <vector> 
#include <algorithm>
#include <numeric>

#define FOR(i,a,b) for(i=(a);i<(b);++i) 
#define FORR(i,a,b) for(i=(a);i>(b);--i)
#define REP(i,n) for(i=0;i<(n);++i)
#define REPR(i,n) for(i=(n);i>0;--i)
#define ll long long
#define INT_MAX 2147483647
#define LL_MAX 9223372036854775807

using namespace std;

long long GCD(long long a, long long b) {
	if (a < b)
		swap(a, b);
	if (b == 0) return a;
	else return GCD(b, a % b);
}
bool sosuu_check(int num) {
	int i;
	for (i = 2; i <= sqrt(num); ++i) {
		if (num%i == 0)
			return false;
	}
	return (num < 2) ? false : true;
}
int main() {
	int a, b, c;
	cin >> a >> b >> c;
	if (a >= b)
		if (a >= c)
			cout << a * 10 + b + c << endl;
		else if (b >= c)
			cout << b * 10 + a + c << endl;
		else
			cout << c * 10 + a + b << endl;
	else
		if (b >= c)
			cout << b * 10 + a + c << endl;
		else
			cout << c * 10 + a + b << endl;
  return 0;
}

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

int main()
{
    ll X;
    cin >> X;
    ll years = 1;
    ll interest = 100 * 1.01;
    while(1)
    {
        if(X <= interest)
        {
            cout << years << endl;
            break;
        }
        else
        {
            years++;
            interest *= 1.01;
        }
    }

    return 0;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
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; }

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i, 0, N) cin >> x[i];
  rep(i, 0, N) x[i] -= X;
  int ans =  x[0];
  rep(i, 0, N) ans = __gcd(ans, abs(x[i]));
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
N = int(input())
T, A = map(int, input().split())		# 5 7
H = list( map(int, input().split()) )	# 1 2 3 4 5 ...

#print(N,T,A)
#print(*H)

H = list(map(lambda x: abs(T-(0.006*x)-A), H) )	#=> [2, 4, 6, 8]
#print(*H)

ans = min(H)
#print(ans)

i=0
for i in range(N):
	if(ans==H[i]):break

print(int(i+1))



Measured memory_bytes: 3060
#include <iostream>

int cnt = 0;

void selectionSort(int A[], int N){
    int min;
    int tmp;
    for(int i=0;i<N;i++){
        min = i;
        for(int j=i;j<N;j++){
            if(A[min]>A[j]){
                min = j;
            }
        }
        if(i!=min){
            tmp = A[i];
            A[i] = A[min];
            A[min] = tmp;
            cnt++;
        }
    }
}

int main(){
    int N;
    std::cin >> N;
    int A[N];
    for(int i=0;i<N;i++){
        std::cin >> A[i];
    }
    selectionSort(A,N);

    for(int i=0;i<N;i++){
        std::cout << A[i];
        if(i==N-1){
            std::cout << std::endl;
        }else{
            std::cout << " ";
        }
    }
    std::cout << cnt << std::endl;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define debug(x) cout<<(#x)<<"="<<(x)<<", ";
#define debug1(x) debug(x) cout<<'\n';
#define debug2(x1, x2) debug(x1) debug(x2) cout<<'\n';
#define debug3(x1, x2, x3) debug(x1) debug(x2) debug(x3) cout<<'\n';
#define debug4(x1, x2, x3, x4) debug(x1) debug(x2) debug(x3) debug(x4) cout<<'\n';
#define debug5(x1, x2, x3, x4, x5) debug(x1) debug(x2) debug(x3) debug(x4) debug(x5) cout<<'\n';

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<int, int, lli> tiil;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;

int main(){
	fast_io 
	int r; cin>>r;
	cout<<r*r;
	
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    map<string, int> cnt;
    for(int i = 0; i < N; i++){
        string s; cin >> s;
        cnt[s]++;
    }
    int M; cin >> M;
    map<string, int> b;
    for(int i = 0; i < M; i++){
        string t; cin >> t;
        cnt[t]--;
    }
    int ans = 0;
    for(auto p : cnt){
        ans = max(ans, p.second);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <bitset>
#include <deque>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <iterator>
#include <string>
#include <chrono>
#include <random>
#include <tuple>
#include <utility>
#include <fstream>

const long INF = (1l << 30);
const long LINF = (1l << 60);

char c;
int main(){
    std::cin >> c;
    if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'){
    printf("vowel\n");
    }else{
    printf("consonant\n");
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;string s;cin >> n>>s;
    rep(i,4){
        string a;
        if(i%2==0)a.pb('S');
        else a.pb('W');
        if(i>=2)a.pb('S');
        else a.pb('W');
        rep(j,n-2){
            char x=s[j+1];
            if(x=='o'){
                if(a[j+1]=='S'){
                    a.pb(a[j]);
                }
                else {
                    if(a[j]=='S')a.pb('W');
                    else a.pb('S');
                }
            }
            if(x=='x'){
                if(a[j+1]=='W'){
                    a.pb(a[j]);
                }
                else {
                    if(a[j]=='S')a.pb('W');
                    else a.pb('S');
                }
            }
        }
        bool b=false;
        if(s[0]=='o'){
            if(a[0]=='S'){
                if(a[n-1]==a[1])b=true;
            }
            else if(a[n-1]!=a[1])b=true;
        }
        if(s[0]=='x'){
            if(a[0]=='S'){
                if(a[n-1]!=a[1])b=true;
            }
            else if(a[n-1]==a[1])b=true;
        }
        bool c=false;
        if(s[n-1]=='o'){
            if(a[n-1]=='S'){
                if(a[n-2]==a[0])c=true;
            }
            else if(a[n-2]!=a[0])c=true;
        }
        if(s[n-1]=='x'){
            if(a[n-1]=='S'){
                if(a[n-2]!=a[0])c=true;
            }
            else if(a[n-2]==a[0])c=true;
        }
        if(c&&b){
            cout <<a <<endl;
            return 0;
        }
    }
    cout << -1 <<endl;
}

Measured memory_bytes: 640
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]

ans = sum(b)
for i in range(n - 1):
    if a[i] == a[i + 1] - 1:
        ans += c[a[i] - 1]

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;

int main(){
	int n;
	cin >> n;
	ll m=0,a=0,r=0,c=0,h=0;
	ll D[5];
	int P[10] = {0,0,0,0,0,0,1,1,1,2};
	int Q[10] = {1,1,1,2,2,3,2,2,3,3};
	int R[10] = {2,3,4,3,4,4,3,4,4,4};
	for(int i=0;i<n;i++){
		string s;
		cin >> s;
		if(s[0]=='M') m++;
		if(s[0]=='A') a++;
		if(s[0]=='R') r++;
		if(s[0]=='C') c++;
		if(s[0]=='H') h++;
	}
	D[0]=m, D[1]=a,D[2]=r, D[3]=c, D[4]=h;
	ll res =0;
	for(ll d=0;d<10;d++)
		res+=D[P[d]]*D[Q[d]]*D[R[d]];
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder
{
	class Programs
	{
		static void Main ()
		{
			var inp = Array.ConvertAll (Console.ReadLine ().Split (), int.Parse);
			var list = new List<Tuple<int,int>> ();
			for (int i = 0; i < inp [1]; i++) {
				var temp = Array.ConvertAll (Console.ReadLine ().Split (), int.Parse);
				list.Add (new Tuple<int,int> (temp [0], temp [1]));
			}
			list = list.OrderBy (f => f.Item2).ToList ();
			int removeBridge = list [0].Item2-1;
			int ans = 1;
			for (int i = 1; i < list.Count (); i++) {
				if (list [i].Item1 > removeBridge) {
					removeBridge = list [i].Item2 - 1;
					ans++;
				}
			}
			Console.WriteLine (ans);
		}
	}
}

Measured memory_bytes: 26948
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n); std::vector<i64> a(n + 1), b(n);
	for(int i = 0; i < n + 1; i++) scanf("%d", &a[i]);
	for(int i = 0; i < n; i++) scanf("%d", &b[i]);
	
	i64 ans = 0;
	for(int i = 0; i < n; i++) {
		i64 tmp = std::min(a[i], b[i]);
		a[i] -= tmp;
		b[i] -= tmp;
		ans += tmp;
		
		tmp = std::min(a[i + 1], b[i]);
		a[i + 1] -= tmp;
		b[i] -= tmp;
		ans += tmp;
	}
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 1792
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// g++ hoge.cpp -std=c++17 -I . でコンパイルできる
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
//#include <atcoder/all>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
//using namespace atcoder;
typedef pair<ll,ll> P;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,k,x,y,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>a>>b>>c>>d;
    cout<<max(a*c,max(a*d,max(b*c,b*d)))<<endl;

    return 0;
}


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

ds = {}
dt = {}
for i in range(len(S)):
    if S[i] not in ds:
        ds[S[i]] = []
    if T[i] not in dt:
        dt[T[i]] = []
    ds[S[i]].append(i)
    dt[T[i]].append(i)

ans = 'Yes'
ds = ds.values()
dt = dt.values()
for x in ds:
    if x not in dt:
        ans = 'No'
        break

print(ans)

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


int main() {

    int N;
    cin >> N;

    long long ans = 1;
    vector<int> num(1001,0);
    for(int i = 2;i <= N;i++) {
        int n = i;
        for(int j = 2;j <= i;j++) {
            while(n % j == 0) {
                n /= j;
                num.at(j)++;
            }
            if(n == 1) break;
        }
    }

    for(int i = 2;i <= N;i++){
        if(num.at(i) != 0) {
            ans *= (num.at(i) + 1);
            ans %= 1000000007;
        }
    }

    cout << ans << endl;
    
}   

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(void){
  int n,avec[100],bvec[100],i;
  double abvalue,dis1=0,dis2=0,dis3=0,dis=0;
 
  scanf("%d",&n);
  for(i=0;i<n;i++)  scanf("%d",&avec[i]);
  for(i=0;i<n;i++)  scanf("%d",&bvec[i]);
 
  for(i=0;i<n;i++){
    abvalue=fabs(avec[i]-bvec[i]);
    dis1+=abvalue;
    dis2+=pow(abvalue,2);
    dis3+=pow(abvalue,3);
    if(abvalue>dis)  dis=abvalue;
  }
  dis2=sqrt(dis2);  dis3=cbrt(dis3);
 
  printf("%f\n%f\n%f\n%f\n",dis1,dis2,dis3,dis);
 
  return 0;
}

Measured memory_bytes: 708
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (a), _end_ = (b); i < _end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const LL mod = 1e9 + 7;

int n; LL ans;
char s[2][60];
bool c[60];
int main()
{
#ifdef ANONYM
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int rtime = clock();
#endif

    scanf("%d", &n);
    scanf("%s%s", s[0], s[1]);
    REP(i, 0, n) {
        if(s[0][i] == s[1][i]) c[i] = true;
    }
    int cur = 0; bool last = false;
    if(c[0]) ans = 3, cur++, last = true;
    else ans = 6, cur += 2, last = false;
    while(cur <= n-1) {
        if(c[cur] && last) ans = ans*2%mod, cur++, last = true;
        else if(c[cur] && !last) cur++, last = true;
        else if(!c[cur] && last) ans = ans*2%mod, cur += 2, last = false;
        else if(!c[cur] && !last) ans = ans*3%mod, cur += 2, last = false;
    }
    printf("%lld\n", ans);

#ifdef ANONYM
    debug("time: %d\n",int(clock() - rtime));
#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int,int> mii;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = b-1; i >= a; i--)
#define F0Rd(i,a) for (int i = a-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
 
const int MOD = 1000000007;
double PI = 4*atan(1);

set<int> k;
mii pos;
int ans = 0;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	int N; cin >> N;
	vi a(N);
	F0R(i,N) {
		cin >> a[i];
		k.insert(a[i]);
	}
	int cur = 0;
	for (int i: k) pos[i] = cur++;
	F0R(i,N) if (pos[a[i]] % 2 == 0 && i % 2 == 1) ans++;
	cout << ans;
}

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

typedef unsigned uint;
typedef long long INT;
typedef unsigned long long UINT;
const int INF = 1001001001;
const INT INFLL = 1001001001001001001LL;

 int in() { int x; scanf("%d", &x); return x; }
double fin() { double x; scanf("%lf", &x); return x; }
INT lin() { INT x; scanf("%lld", &x); return x; }

int main(){
    int a, b, c;
    double fa, fb, fc;
    char S[128], sa[128], sb[128], sc[128];
    // int N = in();
    // int K = in();
    // scanf("%s", S);

    int K = in();
    int A = in();
    int B = in();

    bool bOK = false;
    for (int i = A; i <= B; ++i) {
        if (i % K == 0) {
            bOK = true;
            break;
        }
    }



    printf(bOK ? "OK" : "NG");


    return 0;
}







Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <bitset>
#include <sstream>
#include <cstdlib>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <climits>
using namespace std;

#define eps 1e-8
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<vector<int>> vvi;


int main() {
    int x, a, b;
    cin >> x >> a >> b;

    if (b <= a) {
        cout << "delicious";
    } else if (b - a <= x) {
        cout << "safe";
    } else {
        cout << "dangerous";
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[100000009];
int main()
{
	int t;
	while(cin>>t)
	{
		int con=0,num=0;
		for(int i=1;i<=t;++i)
		{
			cin>>a[i];
		}
		int k = a[1];
		for(int i =2;i<=t;++i)
		{
			if(k>=a[i])
			{
				num++;
				k=a[i];
			}
			if(k<a[i])
			{
				con = max(num,con);
				num = 0;
				k = a[i];
			}
		}
		con = max(con,num);
		cout<<con<<endl;
	}
}

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

int R, C;
int dist[1005][1005], ans;
int sm = 0x3f3f3f3f, bg;

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

int main() {
  ios_base::sync_with_stdio(0);
  cin >> R >> C;
  queue<pair<int, int>> q;
  char tmp;
  for(int i = 0; i < R; i++){
    for(int j = 0; j < C; j++){
      cin >> tmp;
      if(tmp == '#'){
        dist[i][j] = 0;
        q.push(make_pair(i, j));
      }else dist[i][j] = 0x3f3f3f;
    }
  }

  while(!q.empty()){
    int ux = q.front().first;
    int uy = q.front().second;
    q.pop();

    for(int i = 0; i < 4; i++){
      int vx = ux + dx[i];
      int vy = uy + dy[i];
      if(vx >= 0 && vx < R && vy >= 0 && vy < C && dist[vx][vy] > dist[ux][uy] + 1){
        q.push(make_pair(vx, vy));
        dist[vx][vy] = dist[ux][uy] + 1;
        ans = max(ans, dist[vx][vy]);
      }

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

Measured memory_bytes: 12432
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Scanner;
import java.util.TreeSet;

import javax.print.attribute.standard.MediaSize.Other;
import javax.xml.bind.ParseConversionEvent;

public class Main {

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

		char[] input = sc.next().toCharArray();
		
		boolean first_w = input[0] == 'o';
		
		int length = 1;
		char prev = input[0];
		for(int i = 1; i < input.length; i++){
			if(prev != input[i]){
				length++;
				prev = input[i];
			}
		}
		
		if(length % 2 == 0 || first_w){
			System.out.println('o');
		}else{
			System.out.println('x');
		}
		
	}

}

Measured memory_bytes: 17320
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
 
using namespace std;
typedef long long int lli;
 
int main(){
	string S;
	cin>>S;
	int l=(int)S.length();
	string T;
	rep(i,l){
		int pat=(int)T.length();
		if(S[i]=='0')T.push_back('0');
		if(S[i]=='1')T.push_back('1');
		if(S[i]=='B'&&pat!=0)T.pop_back();
	}
	int k=(int)T.length();
	rep(i,k)cout<<T[i];
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
typedef long long ll;
typedef struct data {
    ll x,y;
    bool operator<(const data& a) const
    {
        return x < a.x;
    }
} stu;



ll n,m,k,w;

void solve(){
    string x,y;
    cin >> x >> y ;

    vector<vector<int>> dp(3021, vector<int>(3021));
    for (int i = 1; i <=x.size(); ++i)
    {
        for(int j = 1 ; j <= y.size();j++){
            if(x[i-1]==y[j-1]){
                dp[i][j]=1+dp[i-1][j-1];
            }else{
                dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
            }
        }
    }
    int ans=0;
    int i=x.size(), j ;

    for (int i = 0; i <= y.size(); ++i)
    {
        if(dp[x.size()][i]>=ans){
            j=i;
            ans=dp[x.size()][i];
        }
    }
        if(ans==0){
        cout << "" ;
        return ;
        }
    string answer="";
    while(i>0&&j>0){
        if(x[i-1]==y[j-1]){
            answer =answer+x[i-1];
            i--;
            j--;
        }else if(dp[i][j-1]>dp[i-1][j]){
            j--;
        }else{
            i--;
        }
    }
    for (int i = answer.size()-1; i >=0 ; i--)
    {
        cout << answer[i];
    }
}




int main() {


        //clock_t startTime = clock();

    solve();
    //cout << double( clock() - startTime ) / (double)CLOCKS_PER_SEC<<  endl;    
    return 0;
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  int A, B, C, D;
  cin >> A >> B >> C >> D;
  cout << max(0, min(B, D) - max(A, C)) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int f(int x){
    int p=0;
    while(x){
        p+=x%10;
        x/=10;
    }
    return p;
}
int main(void){
    int n;
    cin>>n;
    int ans=1e9;
    for(int i=1;i<=n/2;i++){
        ans=min(ans,f(i)+f(n-i));
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define Repr(i, n, a) for (int i = (n); i >= (a); i--)
#define rep(i, n) Rep(i, 0, n)
#define repr(i, n) Repr(i, n, 0)
#define all(a) a.begin(), a.end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;

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

    int n;
    cin >> n;
    vector<int> a(n);
    int cnt = 0, sum = 0;
    bool f = false;
    rep(i, n)
    {
        cin >> a[i];
        if (a[i] == 0)
            f = true;
        if (a[i] < 0)
            cnt++;
        a[i] = max(a[i], -a[i]);
        sum += a[i];
    }
    if (f || cnt % 2 == 0)
    {
        cout << sum << endl;
        return 0;
    }
    sort(all(a));
    sum -= 2 * a[0];
    cout << sum << endl;
}

Measured memory_bytes: 1024