akhauriyash/Code-Regression huggingface dataset:
import sys
n, k = map(int,input().split())
a = [int(x) for x in input().split()]

vis_ti = [-1] * n
vis_at = [0]
now = 0

for i in range(1, k+1):
  now = a[now] - 1
  if vis_ti[now] >= 0:
    bgn = vis_ti[now]
    print(vis_at[bgn + (k - bgn) % (i - bgn)] + 1)
    sys.exit()
  vis_ti[now] = i
  vis_at.append(now)

print(vis_at[-1]+1)


Measured memory_bytes: 32328
#include<stdio.h>
#include<string.h>
#define LEN 100005

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

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    for (i = 1; i <= n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while (head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t > 0) enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    
    return 0;
}

Measured memory_bytes: 10756
#include<bits/stdc++.h>
using namespace std;
int main() {
	int n,a[100000]={false},l,r,g=0;
	cin>>n;
    for(int i=1; i<=n; ++i) {
        cin>>l>>r;
        g+=r-l+1;
    }
    cout<<g<<'\n';
	return 0;
}

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

public class Program
{
    public void Proc() {

        Reader.IsDebug = false;
        int[] inpt = Reader.ReadLine().Split(' ').Select(a=>int.Parse(a)).ToArray();
        Console.WriteLine(Math.Max(inpt[0] * inpt[1], inpt[2]*inpt[3]));


    }



    public class Reader {
        public static bool IsDebug = true;
        private static System.IO.StringReader SReader;
        private static string InitText = @"

3 5 2 7


";
        public static string ReadLine() {
            if(IsDebug) {
                if(SReader == null) {
                    SReader = new System.IO.StringReader(InitText.Trim());
                }
                return SReader.ReadLine();
            } else {
                return Console.ReadLine();
            }
        }
    }
    public static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}


Measured memory_bytes: 2776
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>


using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>



ll n, s[110000], pos[110000], ans[110000], ans2[110000];
set<ll> se;
int main() {
	cin >> n;
	REP(i, n) cin >> s[i];
	REP(i, n) {
		pos[s[i]] = i;
	}
	se.insert(-1);
	se.insert(n);
	se.insert(pos[n]);
	FORR(i, n - 1, 1) {
		auto r = se.upper_bound(pos[i]);
		auto l = se.lower_bound(pos[i]);
		ll a = 1, b = 1, c = 1, d = 1;
		if (r != se.end()) {
			//cout << *r << " r" << endl;
			b = *r - pos[i];
			auto r2 = se.upper_bound(*r);
			if (r2 != se.end()) {
				d = *r2 - *r;
				if (*r == n)d = 0;
			}
			else d = 0;
		}
		if (l != se.begin()) {
			l--;
			//cout << *l << " l" << endl;
			a = pos[i] - *l;
			auto l2 = se.lower_bound(*l);
			if (l2 != se.begin()) {
				l2--;
				c = *l - *l2;
				if (*l == -1)c = 0;
			}
			else c = 0;
		}
		else b = 0;
		//cout << a << " " << b << " " << c << " " << d << endl;
		ans[i] = (b * c + a * d) * i;
		se.insert(pos[i]);
	}
	ll out = 0;
	//REPO(i, n) {
	//	cout << ans[i] << " " << i << endl;
	//}
	REPO(i, n) {
		out += ans[i];
	}
	cout << out << endl;
}
	


Measured memory_bytes: 7296
#include<iostream>
#include<map>
#include<string.h>
#include<queue>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<cstdlib>
#include<math.h>
#include<set>
#include<array>
using namespace std;

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



#define rep(n) for(int i=0;i<n;i++)
typedef pair<int, int> pii;

typedef long long ll;
typedef pair<ll, ll>pll;
const int MOD = 1000000007;
const int INF = 1 << 29;

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

int main() {
	ll ans = 1;
	ll n, d[100001];
	cin >> n;
	rep(n) {
		cin >> d[i];
		if (d[i] == 0 && i != 0)ans = 0;
	}
	if (d[0] != 0)ans = 0;
	sort(d, d + n);
	ll cnt = 1, cnt1 = 1;
	if (d[0] != 0)ans = 0;
	for (ll i = 1; i<n; i++) {

		if (d[i] == 0)ans = 0;
		if (d[i] == d[i - 1] + 1) {
			ans *= modpow(cnt, cnt1, 998244353);
			ans %= 998244353;
			cnt = cnt1;
			cnt1 = 1;
		}
		else if (d[i] == d[i - 1]) {
			cnt1++;
		}
		else ans = 0;
	}
	ans *= modpow(cnt, cnt1, 998244353);
	cout << ans % 998244353 << endl;

	return 0;

}


Measured memory_bytes: 1024
using System;
using System.Collections.Generic;
using System.Numerics;
using System.Linq;
using System.Text;
using static System.Math;

class MainClass
{

    public static void Main(string[] args)
    {
        var left = new StringBuilder("");
        var right =new StringBuilder( "");
        var leftISleft = true;
        var S = LnStr();
        var Q = LnInt();
        var Ts = new int[Q];
        var Fs = new int[Q];
        var Cs = new string[Q];
        for (int i = 0; i < Q; i++) { var _ = LnStrs(); Ts[i] = int.Parse(_[0]); if (_.Length > 1) { Fs[i] = int.Parse(_[1]); Cs[i] = _[2]; } }
        for (int i = 0; i < Q; i++)
        {
            if (Ts[i] == 1)
            {
                leftISleft = !leftISleft;
            }
            else
            {
                if (Fs[i] == 1)
                {
                    if (leftISleft)
                        left.Append(Cs[i]);
                    else
                        right.Append(Cs[i]);
                }
                else
                {
                    if (!leftISleft)
                        left.Append(Cs[i]);
                    else
                        right.Append(Cs[i]);
                }
            }
        }
        var result = "";
        if (leftISleft)
        {
            result = new string(left.ToString().Reverse().ToArray()) + S + right;
        }
        else
        {
            result = new string(right.ToString().Reverse().ToArray()) + new string(S.Reverse().ToArray()) + left;
        }
        print(result);
    }



    public static void print(object obj) { Console.WriteLine(obj); }
    public static long Gcd(long a, long b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int Gcd(int a, int b) { if (a > b) { var r = a % b; if (r == 0) return b; else return Gcd(b, r); } else { var r = b % a; if (r == 0) return a; else return Gcd(a, r); } }
    public static int[] LnInts() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new int[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = int.Parse(vs[i]); return ins; }
    public static int LnInt() { var vs = Console.ReadLine().Trim(); return int.Parse(vs); }
    public static long[] LnLngs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); var ins = new long[vs.Length]; for (int i = 0; i < vs.Length; i++) ins[i] = long.Parse(vs[i]); return ins; }
    public static long LnLng() { var vs = Console.ReadLine().Trim(); return long.Parse(vs); }
    public static string[] LnStrs() { var vs = Console.ReadLine().Trim().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); return vs; }
    public static string LnStr() { var vs = Console.ReadLine().Trim(); return vs; }
}




Measured memory_bytes: 32432
#include <bits/stdc++.h>
using namespace std;
using VVI = vector<vector<int>>;
using VI = vector<int>;
const static string el = "\n";
int h,w,k;
int result = 0;
int main ()
{
  int n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0;i < n;i++) 
  {
    long long tmp; cin >> tmp;
    a[i] = tmp;
  }
  
  sort(a.begin(), a.end(), greater<long long>());
  queue<vector<long long>> que;
  long long result = 0;
  if (n == 2) {
    cout << a[0] << endl;
    return 0;
  }
  if(n == 3) {
    cout << a[0] + a[1] << endl;
    return 0;
  }
  que.push(vector<long long> {a[0], a[1]});
  que.push(vector<long long> {a[0], a[2]});
  que.push(vector<long long> {a[1], a[2]});
  
  result += a[0];
  result += a[1];
  
  for (int i = 3;i < n;i++) 
  {
    vector<long long> tmp = que.front();
    // cout << tmp[0] << " " << tmp[1] << " " << a[i] << endl;
    que.pop();
    que.push(vector<long long> {tmp[0], a[i]});
    que.push(vector<long long> {tmp[1], a[i]});
    result += min(tmp[0], tmp[1]);
  }

  cout << result << endl;
}

Measured memory_bytes: 15988
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace ABC
{
    class ABC167D
    {
        const string FILE = "/tmp/data.txt";

        static void Main(string[] args)
        {
#if DEBUG
            Console.SetIn(new StreamReader(FILE));
#endif
            string line;
            string[] sa;
            line = Console.ReadLine();
            sa = line.Split(' ');
            int n = int.Parse(sa[0]);
            long k = long.Parse(sa[1]);

            int[] a = new int[n];
            
            line = Console.ReadLine();
            sa = line.Split(' ');

            for (int j = 0; j < n; ++j)
            {
                a[j] = int.Parse(sa[j]) - 1;
            }

//            for (int k2 = 0; k2 < 15; ++k2)
//            {
//                Console.WriteLine(proc(n, k2, a));
//            }

            Console.WriteLine(proc(n, k, a));

#if DEBUG
            Console.WriteLine();
#endif
        }

        static int proc(int n, long k, int[] a)
        {
            long[] visited = new long[n];
            bool checkVisited = true;
            for (int i = 0; i < n; ++i)
            {
                visited[i] = -1;
            }
            int current = 0;
            for (long i = 0; i < k; ++i)
            {
                current = a[current];
                if (checkVisited && visited[current] >= 0)
                {
                    long loop = i - visited[current];
                    if (loop == 0)
                    {
                        break;
                    }
                    long rest = k - i - 1;
                    if (rest > loop)
                    {
                        long nextI = k - (rest % loop) - 1;

//                        Console.WriteLine("\t" + current + " " + i + " " + rest + " " + (rest % loop) + " " + nextI);

                        i = nextI;
                    }
                    checkVisited = false;
                }
                visited[current] = i;
            }
            return current + 1;
        }
    }
}


Measured memory_bytes: 43876
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */

public class Main {
    public static void main(String[] args) {
        InputStream    inputStream    = System.in;
        OutputStream outputStream = System.out;
        InputReader    in                      = new InputReader(inputStream);
        PrintWriter      out                    = new PrintWriter(outputStream);
        Task                 solver               = new Task();
        solver.solve(1, in, out);
        out.close();
    }

    static class Task {
    	public void solve(int testNumber, InputReader in, PrintWriter out) {
    		int A = in.nextInt();
    		int B = in.nextInt();
    		int C = in.nextInt();
    		int D = in.nextInt();
    		if(A + B > C + D) {
    			out.println("Left");
    		}else if(A + B < C +D) {
    			out.println("Right");
    		}else {
    			out.println("Balanced");
    		}
    	}
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 22996
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
        
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
        
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        
        if x == y:
            return
        
        if self.parents[x] > self.parents[y]:
            x,y = y,x
            
        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def size(self, x):
        return -self.parents[self.find(x)]
    
    def same(self, x, y):
        return self.find(x) == self.find(y)

def main():
    n, m = map(int,input().split())
    ab = [tuple(map(int,input().split())) for _ in range(m)]

    uf = UnionFind(n)

    ans = [n*(n-1)//2]

    for a,b in ab[::-1]:
        sa,sb=uf.size(a-1),uf.size(b-1)
        if uf.same(a-1,b-1):
            ans.append(ans[-1])
        else:
            ans.append(ans[-1]-sa*sb)
        uf.union(a-1,b-1)
        
    for i in range(1,m+1):
        print(ans[-(i+1)])
main()

Measured memory_bytes: 29244
#include <stdio.h>

#define N 1000000

int G[N];
int cou=0,num=0;

void insertsort(int *A,int n,int g){
  int i,j,v;

  for(i=g;i<n;i++){
    v=A[i];
    j=i-g;
    while(j>=0 && v<A[j]){
      A[j+g]=A[j];
      j-=g;
      num++;
    }
    A[j+g]=v;
  }
}

void shell(int *A,int n){
  int h,i;

  for(h=1;;){
    if(h>n) break;
    G[cou]=h;
    h=3*h+1;
    cou++;
  }
  for(i=cou-1;i>=0;i--){
    insertsort(A,n,G[i]);
  }
}

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

  scanf("%d",&n);

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

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

    for(i=cou-1;i>=0;i--){
      printf("%d",G[i]);
      if(i!=0)printf(" ");
    }
  printf("\n");
  printf("%d\n",num);
  for(i=0;i<n;i++) printf("%d\n",A[i]);
  return 0;
}

Measured memory_bytes: 4508
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int L = cin.nextint;
        var S = Convert.ToString(L, 2).Skip(1).ToArray();
        var G = new List<Edge>();
        int n = 1;
        int cnt = 0;
        foreach (var c in S)
        {
            G = G.Select(i => new Edge(i.from, i.to , i.cost * 2)).ToList();
            G.Add(new Edge(cnt, cnt + 1, 0));
            G.Add(new Edge(cnt, cnt + 1, 1));
            n *= 2;
            cnt++;

            if (c == '1')
            {
                G.Add(new Edge(0, cnt, n));
                n++;
            }
        }

        WriteLine($"{cnt + 1} {G.Count}");
        foreach (var item in G)
        {
            WriteLine($"{item.from + 1} {item.to + 1} {item.cost}");
        }
    }

}


struct Edge : IComparable<Edge>
{
    public int from, to, id; public long cost;
    public Edge(int from, int to, long cost)
    {
        this.from = from;
        this.to = to;
        this.cost = cost;
        id = -1;
    }
    public void set_id(int id)
    {
        this.id = id;
    }
    public int CompareTo(Edge e)
    {
        return cost.CompareTo(e.cost);
    }
}
class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

Measured memory_bytes: 13396
#define _USE_MATH_DEFINES
#include<iostream>
#include<fstream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<climits>
#include<set>
#include<map>
#include<cmath>
#include<iomanip>
#include<iterator>
#include<queue>
#include<stack>
#include<cctype>
#include<deque>
#include<time.h>
#include<bitset>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<sstream>
#include<random>

//by Skeef79

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

#pragma warning(disable : 4996)
#pragma comment(linker, "/STACK:16777216")
#define pb push_back
#define en '\n'
#define for0(i,n) for(int i = 0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define vec vector
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

const int INF = 2000000000;
const ll LINF = 2000000000000000000;

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}

template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

template <typename T> void input(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cin >> a[i];
}

template<typename T> void input(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
		for (int j = 0; j < a[i].size(); j++)
			cin >> a[i][j];
}


void solve()
{
	int n, m;
	cin >> n >> m;
	const ll mod = 1e9 + 7;
	set<int> st;
	while (m--)
	{
		int x;
		cin >> x;
		st.insert(x);
	}

	vector<ll> dp(n + 1);
	dp[0] = 1;
	for (int i = 1; i <= n; i++)
		if (st.count(i))
			dp[i] = 0;
		else
		{
			if (i - 1 >= 0)
				dp[i] += dp[i - 1]%mod;
			if (i - 2 >= 0)
				dp[i] += dp[i - 2]%mod;
			dp[i] %= mod;
		}
	cout << dp[n];
}

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

#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif

	int tst = 1;
	//cin >> tst;
	while (tst--)
		solve();

}

Measured memory_bytes: 5760
import sys

if __name__ == '__main__':
	a = int(input())
	l = [[int(i) for i in input().split()] for i in range(2)]
	mx = 0
	for i in range(a):
		t = sum(l[0][0:i+1]) + sum(l[1][i:]) 
		if t > mx:
			mx = t
	print(mx)

Measured memory_bytes: 3060
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    if(a * b % 2 == 0){
        System.out.println("Even");
    }else{
        System.out.println("Odd");
    }    
  }
}

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

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

    int ans = 0;

    rep(i, 4) {
        if (s[i] == '+') {
            ans++;
        } else {
            ans--;
        }
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n=0,x=0,y=0,ans=0;
	scanf("%d",&n);
	if(n>=15){
		x=n*800;
		y=((n/15)*200);
		ans=x-y;
		printf("%d",ans);
	}
	else{
		x=n*800;
		ans=x;
		printf("%d",ans);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
constexpr int mod = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<int> p(9);
	rep(i, n) {
		int a; cin >> a;
		p[min(a / 400, 8)]++;
	}
	int ans = 0;
	rep(i, 8) if (p[i] > 0) ans++;
	cout << ans + (ans == 0 && p[8] > 0 ? 1 : 0) << ' ' << ans + p[8] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long> vl;
#define INF __INT32_MAX__
#define LINF __LONG_LONG_MAX__

int main() {
    int H, W, D;
    cin >> H >> W >> D;
    vector<vector<int>> A(H, vector<int>(W));
    rep(i, H) {
        rep(j, W) {
            cin >> A[i][j];
        }
    }
    int Q;
    cin >> Q;
    vi L(Q), R(Q);
    rep(i, Q) {
        cin >> L[i] >> R[i];
    }

    vector<pair<int, int>> G(H * W + 1);
    rep(i, H) {
        rep(j, W) {
            G[A[i][j]] = make_pair(i + 1, j + 1);
        }
    }

    // rep(i, H * W + 1) {
    //     cout << "i: " << i << ", G[i]: (" << G[i].first << ", " << G[i].second << ")" << endl;
    // }

    vl sum(H * W + 1);
    for (int i = H * W; i > H * W - D; i--) {
        sum[i] = 0;
    }
    for (int i = H * W - D; i >= 1; i--) {
        sum[i] = sum[i + D] + abs(G[i].first - G[i + D].first) + abs(G[i].second - G[i + D].second);
    }

    // rep(i, H * W + 1) {
    //     cout << "i: " << i << ", sum[i]: " << sum[i] << endl;
    // }

    rep(i, Q) {
        cout << (sum[L[i]] - sum[R[i]]) << endl;
    }
}

Measured memory_bytes: 5884
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
N = int(input())
# L = [int(v) for v in input().split()]
# L = [[int(v) for v in input().split()] for _ in range(N)]
# L = [int(input()) for _ in range(N)]
# S = input().strip

x = 0
y = N

p = [None] * N
print(x, flush = True)
p[x] = input().strip()

for _ in range(20):
    m = (x + y) // 2
    print(m, flush = True)

    s = input().strip()
    if s == "Vacant":
        exit()
    else:
        if p[x] == s:
            if (m - x) % 2 == 0:
                x = m
                p[x] = s
            else:
                y = m
                p[y] = s
        else:
            if (m - x) % 2 == 0:
                y = m
                p[y] = s
            else:
                x = m
                p[x] = s

Measured memory_bytes: 4680
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<cmath>
#include<iomanip>
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define sz(a) (int)a.size()
using namespace std;

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

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	vector<bool> dp(k + 1);
	rep(i, k) {
		bool flag = false;
		rep(j, n) {
			if (i + 1 >= a[j] && !dp[i + 1 - a[j]]) {
				flag = true;
			}
		}
		if (flag) dp[i + 1] = true;
		else dp[i + 1] = false;
	}
	if (dp[k]) cout << "First" << endl;
	else cout << "Second" << endl;
}

Measured memory_bytes: 256
n=int(input())
l=[]
keys=['AC','WA','TLE','RE']
for i in range(n):
  x=(input())
  l.append(x)
s=dict.fromkeys(keys, 0)
for i in l:
  if i in s:
    s[i]+=1
for k,v in s.items():
  print(k,"x",v)

Measured memory_bytes: 16324
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>
#include <map>
 
using namespace std;
typedef long long int ll;

//０以上N以下の整数で、ある条件を満たすものの個数を求めよ

int main(){

    ll N , M;
    cin >> N >> M;

    vector<ll > L(M);
    vector<ll > R(M);
    vector<ll > ans(N, 0);
    for(ll i = 0; i < M; i++){
        cin >> L[i] >> R[i];
    }

    sort(L.begin(), L.end());
    sort(R.begin(), R.end());

    if(L[M-1] > R[0]){
        cout << 0 << endl;
    }else{
        cout << R[0] - L[M-1] + 1 << endl;
    }

} 

Measured memory_bytes: 2560
N = int(input())
N_List = list(map(int,input().split()))
ct = 0
for i in range(1,N-1):
    if (N_List[i] > N_List[i-1]) & (N_List[i] < N_List[i+1]):
        ct += 1
    elif (N_List[i] < N_List[i-1]) & (N_List[i] > N_List[i+1]):
        ct += 1


print(ct)


Measured memory_bytes: 9128
#include <bits/stdc++.h>
using namespace std;
#define QOEINDIEDIS freesteed
#define rep(i,a,n) for (int i=a;i<n;i++)
#define pb push_back
#define fill(x,c) memset(x,c,sizeof(x))
#define fi first
#define se second
#define sz(A) (int)(A.size())
#define all(x) (x).begin(),(x).end()
#define caset int ___T; cin>>___T; for(int cs=1;cs<=___T;cs++)
#define get(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
typedef long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
const ll mod=1e9+7;
const int Max = 1e6+10;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int N, M, K, p[20][1010];
int sum(int L1,int R1,int L2,int R2){
    return  p[L2][R2] + p[L1 - 1][R1 - 1] - p[L1 - 1][R2] - p[L2][R1 - 1] ;
}
void solve(){
	cin>>N>>M>>K;
	rep(i,0,N){
		string s;
		cin>>s;
		rep(j,0,M){
			if(s[j]=='1')p[i+1][j+1] = 1;
		}
	}
	for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i][j - 1]; }
    for (int i = 1; i <= N; i++) { for (int j = 1; j <= M; j++) p[i][j] += p[i - 1][j]; }
    int res = 1E9;
	for(int bits = 0 ;bits<(1<<(N-1));bits++){
		int n1 = __builtin_popcount(bits);
		if(n1>=res)continue;//剪枝 
		VI cut;
		for(int i=0;i<N-1;i++){
			if((bits>>i)&1){
				cut.pb(i+1);
			}
		}
		cut.pb(N);
		int  pcol = 1,ans=sz(cut)-1;
		int ok = 1;
		for(int i=1;i<=M;i++){
			int f=1,prow=1;
			for(int j=0;j<sz(cut);j++){
				if(sum(prow,pcol,cut[j],i)>K){
					f = 0;
					break;
				}
				prow = cut[j]+1;
			}
			if(!f){
				ans++;
				if(pcol==i){//Impossible
					ok = 0;
					break;
				}
				pcol = i;
			}
		}
		if(ok)res = min(res,ans);
	}
	cout<<res;
}
int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	//caset{
		solve();
	//}
  	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int all[] = new int[26];
        int i;

        for(i=0;i<all.length; i++) all[i]=0;

        while(sc.hasNext())
        {
            String input = sc.next();
            input = input.toLowerCase();
            input = input.trim();
            char c[] = input.toCharArray();
            
            for(i=0; i<c.length; i++)
            {
                int count=0;
                for(char a='a'; a<='z'; a++)
                {
                    if(c[i]==a)
                    {
                        all[count]++;
                        //System.out.println("got :"+c[i]); 
                    }
                    count++;
                }
            }
        }
        
        int ccount=0;
        for(char a='a'; a<='z'; a++)
        {
            System.out.println(a+" : "+all[ccount]);
            ccount++;
        }

        sc.close();
    }
}


Measured memory_bytes: 26272
N, H = map(int, input().split())
a = [0] * N
b = [0] * N
for i in range(N):
    a[i], b[i] = map(int, input().split())

a_max = max(a)
b.sort(reverse=True)

c = 0
for i in range(N):
    if b[i] > a_max:
        H -= b[i]
        c += 1
    if H <= 0:
        break

if H > 0:
    c += (H + a_max - 1) // a_max

print(c)


Measured memory_bytes: 11312
S=list(input())
K=int(input())
idx=[-1]*10
for i in '123456789':
    if i in S:
        idx[int(i)] = S.index(i)+1
if idx[2:]==[-1]*8 or K < max(idx[2:]):
    print(1)
else:
    print(S[min(i for i in idx[2:]if i>0)-1])

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

int main()
{
    int a, b;
        cin >> a >> b;
        if (a < b){
            cout << "a < b" << endl;
        }
    else if(a > b){
        cout << "a > b" << endl;
    }
    else{
        cout << "a == b" << endl;
    }
    }


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
struct fastio { fastio () { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); } } _io;
template<class T, class U> bool chmax(T& a, const U &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U &b) { if (a > b) { a = b; return 1; } return 0; }

constexpr int MAX = 100100;

int main() {
	int n;
	cin >> n;
	long long ans = 0;
	vector<int> a(MAX, 0);
	for (int i = 0; i < n; i++) {
		int e;
		cin >> e;
		a[e]++;
		ans += e;
	}
	
	
	
	int q;
	cin >> q;
	while (q--) {
		int b, c;
		cin >> b >> c;
		long long val = 1LL * (c - b) * a[b];
		ans += val;
		a[c] += a[b];
		a[b] = 0;
		cout << ans << '\n';
	}

	return 0;
}

Measured memory_bytes: 3716
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int a = in.nextInt();
        final int b = in.nextInt();
        if (b == 1) {
            System.out.println(0);
            return;
        }
        int sum = 0;
        int count = 0;
        while (true) {
            sum += a;
            count++;
            if (sum >= b) {
                break;
            }
            sum--;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23892
h,w,k = gets.split.map(&:to_i)
mod = 10**9+7

dp = (h+1).times.map{Array.new(w,0)}
dp[0][0] = 1

h.times{|i|
  (2**(w-1)).times{|k|
    s = (2**w+k).to_s(2)[1..-1].chars.map{|c|c==?1}
    next if (s.size-1).times.map{|i| s[i] && s[i+1]}.any?
    w.times{|j|
      dp[i+1][j+1] += dp[i][j] if j<w-1 && s[j+1]
      dp[i+1][j-1] += dp[i][j] if 0<j && s[j]
      dp[i+1][j] += dp[i][j] if !s[j+1] && !s[j]
    }
  }
  w.times{|j|
    dp[i+1][j] %= mod
  }
}

p dp[h][k-1]


Measured memory_bytes: 3836
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int n,x,y;
	queue<pii> q;
	int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
	char s[9][9];
	scanf("%d",&n);
	rep(k,n){
		gets(s[0]);
		rep(i,8){
			scanf("%s",s[i]);
		}
		scanf("%d%d",&x,&y);
		q.push(pii(--x,--y));
		s[y][x]='0';
		while(!q.empty()){
			x=q.front().first;
			y=q.front().second;
			q.pop();
			rep(i,4)rep(j,4)if(in(x+dx[i]*j,0,7)&&in(y+dy[i]*j,0,7))
				if(s[y+dy[i]*j][x+dx[i]*j]=='1'){
					s[y+dy[i]*j][x+dx[i]*j]='0';
					q.push(pii(x+dx[i]*j,y+dy[i]*j));
				}
		}
		printf("Data %d:\n",k+1);
		rep(i,8)puts(s[i]);
	}
	return 0;
}

Measured memory_bytes: 1200
from collections import deque

def main():

    players = {
        'a': None,
        'b': None,
        'c': None
    }

    for i in players:
        players[i] = deque(tuple(input()))

    card = 'a'
    while players[card]:
        card = players[card].popleft()

    print(card.upper())


if __name__ == '__main__':
    main()

Measured memory_bytes: 9340
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n); sll(k); sll(q);
	VLL answers(n, 0);
	rep(i, 0, q) {
		sll(a);
		answers[a-1]++;
	}
	rep(i, 0, n) {
		if(q - answers[i] < k)	puts("Yes");
		else	puts("No");
	}
}


Measured memory_bytes: 1408
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <queue>
#include <functional>

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

#define INF 1000000000

int best[123];
vector<vector<pair<int, int>>> cost;

int Dijkstra(int from, int to) {
	rep(i, 123) best[i] = INF;
	best[from] = 0;
	priority_queue < pair<int, int>, vector<pair<int, int>>, greater<pair<int, int>>> pq;

	pq.push(make_pair(0, from));

	while (!pq.empty()) {
		if (pq.top().first >= best[to]) break;
		int top = pq.top().second;
		pq.pop();
		rep(i, cost[top].size()) {
			if (best[cost[top][i].first] > best[top] + cost[top][i].second) {
				best[cost[top][i].first] = best[top] + cost[top][i].second;
				pq.push(make_pair(best[cost[top][i].first], cost[top][i].first));
			}
		}
	}

	if (best[to] == INF) return -1;

	return best[to];
}

int main() {

	for (;;) {

		int n, k;

		scanf("%d %d", &n, &k);
		if (!(n + k)) break;
		cost.clear();
		cost.resize(123);
		rep(i, k) {
			int o;
			scanf("%d", &o);
			if (!o) {
				int a, b;
				scanf("%d %d", &a, &b);
				printf("%d\n", Dijkstra(a, b));
			}
			else {
				int c, d, e;
				scanf("%d %d %d", &c, &d, &e);
				cost[c].push_back(make_pair(d, e));
				cost[d].push_back(make_pair(c, e));
			}
		}
	}

	return 0;
}

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

int a[20];

bool solve(int i, int m, int n)
{
  bool res=false;
  
  if(m == 0){
    return true;
  }
  if(i >= n){
    return false;
  }
  res = solve(i+1,m,n) || solve(i+1,m-a[i],n);
  return res;
}
  
int main(){
  int n;
  cin >> n;

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

  int q;
  cin >> q;

  int m;
  for(int i=0;i < q;i++){
    cin >> m;
    if( solve(0,m,n) ){
      cout << "yes" << endl;
    }
    else{
      cout << "no" << endl;
    }
  }
  return 0;
}


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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll a,b;
    cin >> a >> b;
    ll c = min(a,b);
    ll d = max(a,b);
    while(true){
        if(d%c == 0) break;
        else{
            ll tmp = c;
            c = d%c;
            d = tmp;
        }
    }
    cout << (a/c)*(b/c)*c << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int tl, ta, al, aa;
    scanf("%d %d %d %d", &tl, &ta, &al, &aa);
    
    for (int i = 0;; ++i){
        al -= ta;
        if (al < 1){
            printf("Yes\n");
            break;
        }
        tl -= aa;
        if (tl < 1){
            printf("No\n");
            break;
        }
    }
    
    return 0;
}


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

int main() {
	std::string str, word;
	std::string::size_type index=0, index2;
	std::string::size_type finds, findc, findp;
	bool flg=false;

	// Input a sentence
	while(std::cin >> str) {
		
		index = index2 = 0;
		
		while(1) {
			finds = str.find(" ", index); finds = ( finds==std::string::npos ? str.length() : finds );
			findc = str.find(".", index); findc = ( findc==std::string::npos ? str.length() : findc );
			findp = str.find(",", index); findp = ( findp==std::string::npos ? str.length() : findp );
			// Select Minimum
			index2 = ( finds>findc ? findc : finds );
			index2 = ( index2>findp ? findp : index2 );
			
			word = str.substr( index, index2);
			if( 3<=word.length() && word.length()<=6 ) {
				std::cout << ( flg ? " " : "" ) << word; flg=true;
			}
			
			if(finds==str.length() && findc==str.length() && findp==str.length()) break;
			index += index2+1;
		}
	}

	std::cout << "\n";
	
	return 0;
}

Measured memory_bytes: 1180
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

N, M = map(int, input().split())
YPIs = []
for m in range(M):
    p, y = map(int, input().split())
    YPIs.append((y, p, m))
YPIs.sort()

ans = [None] * M
ctr = Counter()
for y, p, idx in YPIs:
    ans[idx] = "{:06d}{:06d}".format(p, ctr[p] + 1)
    ctr[p] += 1
for a in ans:
    print(a)


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


int main() {
  string S;
  cin>>S;
  int Q;
  cin>>Q;
  int count =0;
  for(int i=0; i<Q; i++){
    int T;
    cin>>T;
    if(T==1) count++;
    else{
      int U;
      char tem;
      cin>>U;
      if(U==2) U=-1;
      cin>>tem;
      if(count%2==1) U*=-1;
      if(U>0) S.insert(S.begin(), tem);
      else S.push_back(tem);
    }
  }
  if(count%2==1) reverse(S.begin(), S.end());
  cout<<S;
}
 


Measured memory_bytes: 900
import numpy as np

N = int(input())
h_list = list(map(int, input().split(" ")))

cost_list = [0]
cost = np.abs(h_list[1] - h_list[0])
cost_list.append(cost)

for i in range(2, N):
    cost1 = np.abs(h_list[i] - h_list[i-1]) + cost_list[i-1]
    cost2 = np.abs(h_list[i] - h_list[i-2]) + cost_list[i-2]
    cost = min(cost1, cost2)
    cost_list.append(cost)

print(cost_list[-1])

Measured memory_bytes: 22736
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int mod=1e9+7;

int n,x[N],inv[N];

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	cin>>n;for(int i=1;i<=n;i++) cin>>x[i];
	inv[1]=1;for(int i=2;i<=n;i++) inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	int ans=0;
	for(int i=1,sum=0;i<n;i++) sum=(sum+inv[i])%mod,ans=(ans+1ll*(x[i+1]-x[i])*sum)%mod;
	for(int i=1;i<n;i++) ans=1ll*ans*i%mod;cout<<ans;
	return 0;
}


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

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }


int dp[100010];

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

    rep(i, s.size()) {
        // 奇数
        if((i+1)%2 == 1) {
            if(s[i] == 'R' || s[i] == 'U' || s[i] == 'D') {
                continue;
            } else {
                cout << "No" << endl;
                return 0;
            }
        } else {
            if(s[i] == 'L' || s[i] == 'U' || s[i] == 'D') {
                continue;
            } else {
                cout << "No" << endl;
                return 0;
            }
        }
    }

    cout << "Yes" << endl;

    return 0;
}



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

typedef long long ll;

ll modpow(ll b, ll x, ll mod)
{
    if (x == 0)
        return 1;

    if (x & 1) {
        return modpow(b*b % mod, x/2, mod) * b % mod;
    } else {
        return modpow(b*b % mod, x/2, mod);
    }
}

#define MOD 1000000007

int main()
{
    ll N, K; cin >> N >> K;
    vector<ll> n(K + 1);

    ll ans = 0;

    for (int i = K; i >= 1; i--) {
        n[i] = modpow(K / i, N, MOD);
        for (int j = 2 * i; j <= K; j += i) {
            n[i] -= n[j];
        }
        ans = (ans + i * n[i]) % MOD;
    }

    while (ans < 0) ans += MOD;

    cout << ans << endl;
}


Measured memory_bytes: 4048
from fractions import gcd

memo = {}
ans = 0

k = int(input())

my_gcd = {}
for i in range(1, k+1):
    for j in range(i, k+1):
        my_gcd[(i, j)] = gcd(i, j)
        my_gcd[(j, i)] = my_gcd[(i, j)]

for a in range(1, k+1):
    for b in range(a, k+1):
        g = my_gcd[(a, b)]
        for c in range(b, k+1):
            g2 = my_gcd[(g, c)]

            if a == b and b == c:
                ans += g2
            elif a == b or b == c or c == a:
                ans += g2*3
            else:
                ans += g2*6

print(ans)


Measured memory_bytes: 81996
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 400005, MAXM = 102, Mod = 1000000007, MAXLog = 20;

int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

	int a, b, c;
	cin >> a >> b >> c;
	
	cout << max(0, c - (a - b)) << '\n';
	
	return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
inputs_set = set([i for i in input().split()])

all_set = set({'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'})
rest_set = all_set - inputs_set

for i in range(N, N*10 + 1):
    if set(str(i)) <= rest_set:
        print(i)
        break

Measured memory_bytes: 3060
N, C, K = map(int, input().split())

T = []

for i in range(N):
    tmp = int(input())
    T.append(tmp)
    
T.sort()
    
ans = 1
now = 1
now_time = T[0]

for i in range(1, N):
    if now==C:
        now=1
        ans=ans+1
        now_time = T[i]
    elif T[i]-now_time<=K:
        now=now+1
    else:
        now=1
        ans=ans+1
        now_time = T[i]
        
print(ans)
        
            

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

/*ll small(ll n,ll k){
    if(min(n,k) == 1) return 0;
    else if(n % k == 0 || k % n == 0) return min(n,k);
    ll temp1,temp2;
    temp1 = max(n,k);
    temp2 = min(n,k);
    small(temp1 % temp2, temp2)
}*/
int main(){
    ll n,k;
    cin >> n >> k;
    if (n > k) n = n % k;
    while(n > abs(n-k)){
        n = min(n, (abs(n-k)));
    }

    cout << n << endl;
}

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

using namespace std ;
	
	
int main () {
	ios_base::sync_with_stdio; 
	cin.tie(0) ; 
	cout.tie(0)  ; 
	int x;  
	cin >> x ; 
	int res = x / 500 ; 
	int sum = res * 1000 ; 
	x = x - ( res* 500 ) ; 
	x /= 5 ; 
	x*= 5;  
	cout << sum + x << endl ; 
	

}


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

int n, m;
string a[60], b[60];

bool match(int x, int y);

int main() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < m; i++) cin >> b[i];

    bool found = false;
    for (int i = 0; i <= n-m; i++) {
        for (int j = 0; j <= n-m; j++) {
            if (match(i, j)) {
                found = true;
            }
        }
    }

    cout << (found ? "Yes" : "No") << endl;
    
    return 0;
}

bool match(int x, int y) {
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < m; j++) {
            if (a[x+i][y+j] != b[i][j]) {
                return false;
            }
        }
    }
    return true;
}


Measured memory_bytes: 256
/*************************************************************************
	> File Name: 3.cpp
	> Author: Knowledge_llz
	> Mail: 925538513@qq.com 
	> Blog: https://blog.csdn.net/Pig_cfbsl 
	> Created Time: 2020/7/13 13:29:28
 ************************************************************************/

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
using namespace std;
int read(){
	char x=getchar(); int u=0,fg=0;
	while(!isdigit(x)){ if(x=='-') fg=1; x=getchar(); }
	while(isdigit(x)){ u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return fg?-u:u;
}
int n,a[2020],num[2020];
LL sum[2020],ans=0;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.in", "r", stdin);
	freopen("output.out", "w", stdout);
#endif
	n=read();
	For(i,1,n){ a[i]=read(); num[a[i]]++; }
	For(i,1,2000) sum[i]=sum[i-1]+num[i];
	For(i,1,n)
		For(j,1,n){
			if(i==j) continue;
			int u=abs(a[i]-a[j]),v=a[i]+a[j];
			int tmp=sum[v-1]-sum[u]-1;
			u=a[i],v=a[j];
			if(u>v) swap(u,v);
			if(v<2*u) --tmp;
			ans+=tmp;
//			printf("%d %d %d\n",a[i],a[j],tmp);
		}
	cout<<ans/6<<endl;
	return 0;
}


Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;cin>>a>>b;
  if(a>=13){
    cout<<b<<endl;
  }else if(6<=a and a<=12){
    cout<<b/2<<endl;
  }else if(a<=5){
    cout<<0<<endl;
  }
}

Measured memory_bytes: 256