akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include<map>	
#include<cstring>
#include<iomanip>
#include <string>
#include <vector>	
#include<unordered_map>
#include<unordered_set>
using namespace std;


typedef long long unsigned llu;
typedef long double ld;
#define ll long long
#define PI 3.14159265358979323846
#define For(i, a, b) for (int i = a, sz = (int)b; i < sz; i++)
#define rFor(i, a, b, c) for (int i = (a); i >= (b); i -= (c))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fill(a, b) memset(a, b, sizeof(a))
#define IO ios_base::sync_with_stdio(false), cin.tie(0),cout.tie(0)
const int mod = 1000000007;
const ll inf = 1000000000009;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);}

//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdoutn
int main()
{
	int a{},b{},c{},n{},ans{};
	cin>>a>>b>>c>>n;
	For(i,1,a+1){if(n==(500*i))ans+=1;}
	For(i,1,b+1){if(n==(i*100))ans+=1;}
	For(i,1,c+1){if(n==(i*50))ans+=1;}
	For(i,1,a+1){For(j,1,b+1){if(n==((i*500)+(j*100)))ans+=1;}}
	For(i,1,a+1){For(j,1,c+1){if(n==((i*500)+(j*50)))ans+=1;}}
	For(i,1,b+1){For(j,1,c+1){if(n==((i*100)+(j*50)))ans+=1;}}
	For(i,1,a+1){
		For(j,1,b+1)
		{
			For(k,1,c+1)
			{
				if(n==((i*500)+(j*100)+(k*50)))ans+=1;
			}
		}
	}
	cout<<ans<<'\n';
	//system("pause");	
	return 0;
}

Measured memory_bytes: 3544
#include<cstdio>
#include<iostream>

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

using namespace std;

template<typename ...> static inline int getchar_unlocked(void) {
    return getchar();
}
#define mygc(c) (c)=getchar_unlocked()

void reader(int& x) {
    int k, m = 0; x = 0;
    for (;;) {
         mygc(k);
         if (k == '-') { m = 1; break; }
         if ('0' <= k&&k <= '9') {
             x = k - '0';
             break;
         }
     }
     for (;;) {
         mygc(k);
         if (k<'0' || k>'9') break;
         x = x * 10 + k - '0';
     }
     if (m) x = -x;
 }

 int a[100000];

int main(){
    int n,m,min=1234567899,d=0,cnt=0;
    reader(n);
    reader(m);
    REP(i,n) reader(a[i]);
    REP(i,n){
        if(min>a[i]){
            min = a[i];
        }else if(d==a[i]-min){
            ++cnt;
        }else if(d<a[i]-min){
            d = a[i] - min;
            cnt=1;
        }
    }
    printf("%d",cnt);
    return 0;
}


Measured memory_bytes: 640
#include<iostream> 
#include <algorithm>
#include <vector>
#include <cstdlib>
#include <sstream>
#include <vector>

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



int main() {
	int n,an=0,bn=0,i=0;
	cin >> n;
	vector<int>a(n);
	vector<int>b(n);
	rep(i, n) {
		cin >> b.at(i);
	}
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	rep(i, n) {
		if (i % 2 == 0) {
			an += b.at(i);
		}
		else {
			bn += b.at(i);
		}
	}
	cout << an - bn << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
vector<int>v[MAX];
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    int n,k;
    cin>>n>>k;
    while(k--)
    {
        int a,b;
        cin>>a>>b;
        v[a].push_back(b);
    }
    for(int i=1; i<=n; i++)
        sort(all(v[i]));
    int mn=INT_MAX,ans=0;
    for(int i=1; i<=n; i++)
    {
        if(mn==i){
            ans++;
            mn=INT_MAX;
        }
        if(v[i].size())
        {
            mn=min(mn,v[i][0]);
        }
    }
    if(mn!=INT_MAX)
        ans++;
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 30152
#include<iostream>
#include<vector>
#include<complex>
#include<algorithm>
#include<set>
#include<map>
#define rep(i,n) for(int i = 0;i < n ; ++i)

using namespace std;

using ll = long long;

struct die{
    int u,d,l,r,b,f;
    die(vector<int> a){
        f=a[0];
        u=a[1];
        l=a[2];
        r=a[3];
        d=a[4];
        b=a[5];

        if(b==0){
            swap(b,f);
            swap(l,r);
        }
        if(d==0){
            int tmp = d;
            d = b; b = u; u = f; f = tmp;
        } 
        if(u==0){
            int tmp = u;
            u = b; b = d; d = f; f = tmp;
        }
        if(l==0){
            int tmp = l;
            l = b; b = r; r = f; f = tmp;
        }
        if(r==0){
            int tmp = r;
            r = b; b = l; l = f; f = tmp;
        }
        int mi = min({u,d,l,r});
        while(u!=mi){
           int tmp = r;
            r = u; u = l; l = d; d = tmp; 
        }
    }
    bool operator==(const die rhs)const{
        return (f==rhs.f&&b==rhs.b&&u==rhs.u&&d==rhs.d&&l==rhs.l&&r==rhs.r);
    }
};

map<string, int> mp;
void solve(int n){
    vector<die> d;
    rep(i,n){
        vector<int> a(6);
        rep(j,6){
            string s;cin>>s;
            a[j]=mp[s];
        }
        die di(a);
        d.push_back(di);
    }
    vector<int> used(n);
    int ans = 0;
    rep(i,n){
        if(used[i]){
            ++ans;
            continue;
        }
        for(int j = i+1;j<n;j++){
            if(d[i]==d[j])used[j]=true;
        }
    }
    cout<<ans<<endl;
}
int main(){
     mp["Cyan"]=0;
     mp["Yellow"]=1;
     mp["Red"]=2;
     mp["Magenta"]=3;
     mp["Green"]=4;
     mp["Blue"]=5;
     int n;
     while(cin>>n,n!=0)solve(n);
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = (int)(n)-1; i >=0; i--)

using ll = long long;

int main(){
  string S; cin>>S;
  int l = S.size();
  int tmp = 1;
  vector<int> res(l);
  rep(i,l){
    if(i==0)continue;
    if(S.at(i)=='R'){
      tmp++;
    }else{

      res.at(i-1)=(tmp-1)/2+1;
      res.at(i)=tmp-((tmp-1)/2+1);
      int tmpl = 1;
      int next_i = i;
      for(int j = i+1; j < l; j++){
        if(S.at(j)=='R'){
          next_i=j;
          break;
        }
        tmpl++;
        if(j==l-1)next_i=j;
      }
      res.at(i-1)+=tmpl-((tmpl-1)/2+1);
      res.at(i)+=(tmpl-1)/2+1;
      i = next_i;
      
      tmp = 1;
    }
  }
  rep(i,l)cout<<res.at(i)<<" ";
  cout<<endl;
}

Measured memory_bytes: 1024
def wczytaj_liste(): 
    wczytana_lista = input()
    lista_znakow = wczytana_lista.split()
    ostateczna_lista = []
    for element in lista_znakow:
        ostateczna_lista.append(int(element))
    return ostateczna_lista 

def atcoder(): 
    N, M = wczytaj_liste()
    odpowiedzi_string = []
    for i in range(M): 
        odpowiedzi_string.append(input())
    odpowiedzi_lista = []
    for string in odpowiedzi_string: 
        zadanie, wynik = string.split()
        nr_zadania = int(zadanie)
        odpowiedzi_lista.append((nr_zadania, wynik))
    rozwiazane_zadania = set()
    zle_rozwiazania = {}
    for i in range(N+1): 
        zle_rozwiazania[i] = 0
    for nr_zadania, wynik in odpowiedzi_lista:
        if nr_zadania not in rozwiazane_zadania: 
            if wynik == 'WA':
                zle_rozwiazania[nr_zadania] += 1
            else: 
                rozwiazane_zadania.add(nr_zadania)
    kary = 0 
    poprawne = len(rozwiazane_zadania)
    for nr_zadania in rozwiazane_zadania: 
        kary += zle_rozwiazania[nr_zadania]
    print(poprawne, kary)

atcoder()

Measured memory_bytes: 81876
import java.io.*;

class Main {
	public static void main(String args[]) {
		try {
			BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			int a[] = new int[10];
			for(int i = 0;i < 10;i++) {
				a[i] = Integer.parseInt(reader.readLine());
				int t = a[i];
				int j = i;
				while(j > 0 && a[j-1] < t) {
					a[j] = a[j-1];
					j--;
				}
				a[j] = t;
			}
			for(int i = 0;i < 3;i++) {
				System.out.println(a[i]);
			}
		}
		catch(IOException e) {
			System.out.println(e);
		}
	}
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vll a(5);
	ll k;
	rep(i, 5) cin>>a[i];
	cin>>k;
	if (a[4]-a[0]<=k){
		cout << "Yay!\n";
	}else{
		cout << ":(\n";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n, m, l, i, j, k, a, b;
		try (Scanner sc = new Scanner(System.in)) {
			n = sc.nextInt();
			m = sc.nextInt();
			l = sc.nextInt();
			int n_m[][] = new int[n][m];
			int m_l[][] = new int[m][l];
			long output[][] = new long[n][l]; //表の配列
			for(i = 0; i < n; i++) {
				for(j = 0; j < m; j++) {
					n_m[i][j] = sc.nextInt();
				}
			}
			for(i = 0; i < m; i++) {
				for(j = 0; j < l; j++) {
					m_l[i][j] = sc.nextInt();
				}
			}
			for(i = 0; i < n; i++) {
				for(j = 0; j < m; j++) {
					for(k = 0; k < l; k++) {
						output[i][k] += n_m[i][j] * m_l[j][k];
						if(j == m - 1) {
							if(k < l - 1) {
								System.out.print(output[i][k] + " ");
							}else {
								System.out.println(output[i][k]);
							}
						}
					}
				}
			}
		}
	}
}



Measured memory_bytes: 53756
#include <iostream>
#include <algorithm>
 
using namespace std;
 
long long L, R;
 
int main(){
    cin >> L >> R;
 
    int ans = 2019;
    for(long long i = L; i < R; i++){
        for(long long j = i + 1; j <= R; j++){
            ans = min(((i % 2019) * (j % 2019)) % 2019, (long long)ans);
            if(ans == 0){
                break;
            }
        }
        if(ans == 0){
            break;
        }
    }
 
    cout << ans << endl;
 
 
    return 0;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)
connects = Array.new(M) { gets.split.map(&:to_i) }
connects += connects.map { |e1,e2| [e2,e1] }

now = 1
visited = [now] # point

stack = [visited]
ans = []

until stack.empty? do
  visited = stack.pop
  remain = N - visited.size
  now = visited[-1]
  1.upto(N) do |i|
    next if i == now
    if connects.include? [now,i]
      unless visited.include? i
        new_visited = visited + [i]
        stack << new_visited
        ans << new_visited if new_visited.size == N
        # p new_visited
      end
    end
  end
end

# p '-----------------------'
p ans.size


Measured memory_bytes: 14756
def merge(A,i,B):#リストAのi番目にリストBを挿入したリストを返す
    A_1=A[0:i]
    A_2=A[i:len(A)]
    return A_1 +B + A_2


str = input()
str =list(str)
n=int(input())
for i in range(0,n):
    order=input().split()
    order[1]=int(order[1])
    order[2]=int(order[2])
    if(order[0]=="print"):
        print("".join(str[order[1]:order[2]+1]))
    elif(order[0]=="replace"):
        del str[order[1]:order[2]+1]
        str=merge(str,order[1],list(order[3]))
    elif(order[0]=="reverse"):
        key=str[order[1]:order[2]+1]
        key.reverse()
        del str[order[1]:order[2]+1]
        str=merge(str,order[1],key)


Measured memory_bytes: 5644
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	b += MOD;
	a += b;
	a %= MOD;
}

int main(void){
	int d,i,n,j,g,p[12],c[12],s[12],tmp,ans=INF,takahashi;
	cin >> d >> g;
	n = (1<<d);
	for(i=0; i<d; ++i){
		cin >> p[i] >> c[i];
		s[i] = (i+1)*100;
	}
	for(i=0; i<n; ++i){
		tmp = 0; takahashi = 0;
		for(j=0; j<d; ++j){
			if(i&(1<<j)){
				tmp += p[j];
				takahashi += p[j]*s[j]+c[j];
			}
		}
		for(j=(d-1); j>=0; --j){
			if(takahashi >= g){
				break;
			}
			if(i&(1<<j)){
				continue;
			}
			tmp += min((g-takahashi-1)/s[j]+1,p[j]);
			takahashi += min((g-takahashi-1)/s[j]+1,p[j])*s[j];
		}
		ans = min(ans,tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include <algorithm>
#include <map> // pair
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    if (a >= k) {
        cout << k << endl;
    } else if (a + b >= k) {
        cout << a << endl;
    } else {
        cout << a - (k - (a + b)) << endl;
    }
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;
int main() {
    string N;  cin >> N;
    bool flag = false;
    if(N[0] == '7') flag = true;
    if(N[1] == '7') flag = true;
    if(N[2] == '7') flag = true;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3628
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;

const lld N = 200043;
const lld MOD = 1000000007;

lld add(lld x, lld y)
{
    x =((x%MOD)+(y%MOD))%MOD;
    while(x >= MOD) x -= MOD;
    while(x < 0) x += MOD;
    return x;
}

lld mul(lld x, lld y)
{
    return ((x%MOD)*(y%MOD))% MOD;
}

lld binpow(lld x, lld y)
{
    lld z = 1;
    while(y)
    {
        if(y & 1) z = mul(z, x);
        x = mul(x, x);
        y >>= 1;
    }
    return z;
}

lld inv(lld x)
{
    return binpow(x, MOD - 2);
}

lld divide(lld x, lld y)
{
    return mul(x, inv(y));
}

// Combinations

/*
lld fact[N];

void precalc()
{
    fact[0] = 1;
    for(lld i = 1; i < N; i++)
        fact[i] = mul(fact[i - 1], i);
}

lld C(lld n, lld k)
{
    return divide(fact[n], mul(fact[k], fact[n - k]));
}
*/
lld h,w,a,b,c,d;
string str[1005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t,i,j;
    //cin>>t;
    t=1;
    while(t--)
    {
        cin>>h>>w;
        cin>>a>>b;
        cin>>c>>d;
        a--,b--,c--,d--;
        for(i=0;i<h;i++)
            cin>>str[i];
        priority_queue<pair<lld,pair<lld,lld>>>q;
        q.push({0,{a,b}});
        lld dist[h][w];
        for(i=0;i<h;i++)
        {
            for(j=0;j<w;j++)
                dist[i][j]=LLONG_MAX;
        }
        dist[a][b]=0;
        while(!q.empty())
        {
            lld x=q.top().second.first;
            lld y=q.top().second.second;
            lld ctr=-q.top().first;
            //cout<<x<<" "<<y<<endl;
            q.pop();
            for(i=-2;i<=2;i++)
            {
                for(j=-2;j<=2;j++)
                {
                    if(i==0 && j==0)
                            continue;
                    if(x+i>=0 && x+i<h && y+j>=0 && y+j<w && str[x+i][y+j]=='.')
                    {
                        lld ctr=1;
                        if((abs(i)==1 && j==0)||(abs(j)==1 && i==0))
                            ctr=0;

                        if(dist[x+i][y+j]>dist[x][y]+ctr)
                        {   dist[x+i][y+j]=dist[x][y]+ctr;
                            q.push({-dist[x+i][y+j],{x+i,y+j}});
                        }
                    }
                }
            }
        }
        if(dist[c][d]==LLONG_MAX)
            cout<<-1<<endl;
        else
            cout<<dist[c][d]<<endl;
    }
}




Measured memory_bytes: 12656
import std.stdio,std.string,std.conv;

int[] value;

string dfs(int left,int right,int i)
{
	if(i == 10) return "YES";
	if(left < value[i])
	{
		return dfs(value[i],right,i+1);
	}
	if(right < value[i])
	{
		return dfs(left,value[i],i+1);
	}
	return "NO";
}


int main()
{
	value.length = 10;
	int n = readln.chomp.to!int;
	foreach(i;0..n)
	{
		string[] s = readln.chomp.split(" ");
		foreach(j;0..10)
		{
			value[j] = s[j].to!int;
		}
		writeln(dfs(0,0,0));
	}
	return 0;
}

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

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



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

    long long int N,a,next;int loop=0,loopout=1;
    long long int K;
    vector<int>A;

    cin>>N>>K;
    rep(i,N){
        cin>>a;
        A.push_back(a);
    }
    a=A.size();
    int B[a+1]={};

    next=A[0];
    rep(i,N){
        if(B[next-1]!=1){
            B[next-1]=1;
            next=A[next-1];
            loopout++;
        }
        else{
            break;
        }
    }
    rep(i,N){
        if(B[next-1]!=2){
            B[next-1]=2;
            next=A[next-1];
            loop++;
        }
        else{
            break;
        }
    }
    if(loopout<K){
        loopout-=loop;
        K-=loopout;
        K%=loop;
        rep(i,K){
            next=A[next-1];
        }
    }
    else{
        next=1;
        rep(i,K){
            next=A[next-1];
        }
    }
    cout<<next<<endl;

    return 0;
}


Measured memory_bytes: 5088
#include<bits/stdc++.h>
#define llu unsigned long long
#define ll long long
#define INF 0x3f3f3f3f
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.141592653589793
using namespace std;

int main()	
{
	#ifdef SANS
		freopen("C:\\Users\\ASUS\\Documents\\Sublime\\input_output\\inputf.txt","r",stdin);
		freopen("C:\\Users\\ASUS\\Documents\\Sublime\\input_output\\outputf.txt","w",stdout);
	#endif
	fast
	int t=1;
	while(t--)
	{
		double r;
		cin>>r;
		cout << fixed <<setprecision(20)<<(2*PI*r)<<endl; 
	}
	#ifdef SANS
		cout<<"\nTime Elapsed:"<<1.0*clock()/CLOCKS_PER_SEC <<"sec\n";
	#endif
}

Measured memory_bytes: 3780
c = ['' for _ in range(3)]
c[0] = list(map(int, input().split()))
c[1] = list(map(int, input().split()))
c[2] = list(map(int, input().split()))
ans = 'Yes'
for i in range(2):
    line = [0 for _ in range(3)]
    column = [0 for _ in range(3)]
    for j in range(3):
        line[j] = c[i + 1][j] - c[i][j]
        column[j] = c[i + 1][j] - c[i][j]
    if len(set(line)) != 1 or len(set(column)) != 1:
        ans = 'No'
        break
print(ans)


Measured memory_bytes: 3064
#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>;
 
const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};
 
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
} comb(1000010);
 
int main() {
  int n, k; cin >> n >> k;
  vector<mint> ans(k+1);
  for (int i = k; i >= 1; i--) {
    ans[i] = mint(k/i).pow(n);
    for (int j = 2; i * j <= k; j++)
      ans[i] -= ans[i * j];
  }
  mint res = 0;
  for (int i = 1; i <= k; i++)
    res += ans[i] * i;
  cout << res.x << endl;
  return 0;
}

Measured memory_bytes: 19628
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/


int main(){
  ll n,k;
  cin >> n >> k;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
    a[i]--;
  }

  vector<int> lp;
  set<int> st;
  int pos = 0;
  while(st.find(pos)==st.end()){
    st.insert(pos);
    lp.emplace_back(pos);
    pos = a[pos];
  }
  vector<int> lp2;
  set<int> st2;
  while(st2.find(pos)==st2.end()){
    st2.insert(pos);
    lp2.emplace_back(pos);
    pos = a[pos];
  }
  ll cnt = lp.size()-lp2.size();

  ll lpn = lp2.size();
  if(k<=cnt){
    cout << lp[k]+1 << endl; return 0;
  }
  k = (k-cnt)%lpn;
  int ans = lp2[k]+1;
  cout << ans << endl; 
  return 0;
}

Measured memory_bytes: 22556
#include <stdio.h>
const int N=3e2+10;
int main(){
    char c[N][N],a[N][N];
    bool f;
    int n,ans=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)scanf("%s",c[i]);
    for(int i=0;i<n;i++){
        f=true;
        for(int j=0;j<n&&f;j++)for(int k=0;k<n&&f;k++)if(c[(j+i)%n][k]!=c[(k+i)%n][j])f=false;
        if(f)ans+=n;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pub push_back
#define x first
#define all(a) a.begin(), a.end()
#define y second
#define mp make_pair
#define ll long long
#define db double   
using namespace std;

int cnt[100007];

int main() {
    srand(time(NULL) + 'D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N');
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);  
    //freopen("expr.in", "r", stdin);
    //freopen("expr.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    while(n--){
    	int x;
    	cin >> x;
    	cnt[x]++;
    	cnt[x + 1]++;
    	cnt[x + 2]++;
    }
    int ma = 0;
    for (int i = 0; i < 100007; i++) ma = max(ma, cnt[i]);
    cout << ma;
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr = ds.begin(); itr != ds.end(); ++itr)
#define mp make_pair
#define INF 2000000000
#define INFL 2000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;

int N, K;
vi a;

// a[n]が必要
bool need(int n) {
	vb can(K, false);
	can[0] = true;
	rep(i, N) {
		if (i == n)continue;
		reprev(j, K - a[i]) {
			can[j + a[i]] = can[j + a[i]] || can[j];
		}
	}

	repl(i, max(0, K - a[n]), K) {
		if (can[i])return true;
	}
	return false;
}

int main() {
	cin >> N >> K;
	a = vi(N);
	rep(i, N)cin >> a[i];

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

	int ans = 0;
	int no = -1, yes = N;
	while (yes - no > 1) {
		int med = (no + yes) / 2;
		if (need(med)) {
			yes = med;
		}
		else {
			no = med;
		}
	}

	cout << yes << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	vector<string> s(3);
	rep(p,3) cin >> s[p];
	vector<queue<int>> q(3);
	rep(p,3)rep(i,s[p].size()){
		char c = s[p][i];
		int x = c - 'a';
		q[p].push(x);
	}
	
	int p = 0;	
	while(q[p].size()){
		int nx = q[p].front();
		q[p].pop();
		p = nx;
	}
	char winner = 'A'+p;
	cout << winner << endl;
}


Measured memory_bytes: 256
// Problem : F - Division or Substraction
// Contest : AtCoder Beginner Contest 161
// URL : https://atcoder.jp/contests/abc161/tasks/abc161_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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

typedef long long   ll;
const ll mod = 1e9 + 7;

#define speedup_IO      ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define forn(i,a,n)     for(ll i = a; i < n; i++)
#define ford(i,n,a)     for(ll i = n; i >= a; i--)
#define pb              push_back
#define lb              lower_bound		// first element >= val(itr) 
#define ub              upper_bound		// first element >  val(itr)
#define pll             pair<ll,ll>
#define all(a)          (a).begin(),(a).end()
#define reset(a,x)      memset(a,x,sizeof(a))	//x can be 0 or -1

ll mypow(ll base, ll exp) {ll res = 1; while (exp) {if (exp & 1) res = (res * base) % mod; exp >>= 1, base = (base * base) % mod;} return res;}
ll gcd(ll a, ll b)  { return b ? gcd(b, a % b) : a;            }
ll mult(ll a, ll b) { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + b % mod) % mod;        }
ll sub(ll a, ll b)  { if (a < 0) {a += mod;} if (b < 0) {b += mod;} return (a % mod + mod - b % mod) % mod;  }

#ifdef LOCAL_TEST
	#include"/home/shrey/debug.h"
#endif

const ll inf = 1e18;
const int nax = 1e5 + 5;

bool check(ll n,ll k)
{
	while(n%k == 0)
	{
		n /= k;
	}
	
	return n%k == 1;
}

void SolveTestCase()
{
	ll n;
	cin>>n;
	
	set<ll>S;
	
	for(ll i=1;i*i<=n;i++)
	{
		if(n%i == 0)
		{
			if(i!=1 && check(n,i) )
			{
				S.insert(i);
			}
			if((n/i)!=1 && check(n,n/i))
			{
				S.insert(n/i);
			}
		}
	}
	
	for(ll i=1;i*i<=n-1;i++)
	{
		if((n-1)%i == 0)
		{
			if(i>1)
			{
				S.insert(i);
			}
			if((n-1)/i>1)
				S.insert((n-1)/i);
		}
	}
	
//	cout<<S;
	
	cout<<S.size();
}

int main()
{
	speedup_IO;

	int t = 1;
	//cin >> t;
	forn(i,0,t)
	{
		SolveTestCase();
	}

	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
n,k = map(int, input().split())
al = list(map(int, input().split()))

def f(x):
    res = 0
    for a in al:
        res += x^a
    return res

# res = 0
# for x in range(k+1):
#     res = max(res,f(x))
# print(res)

cs = []
mi = 0
while (1<<mi)<=k:
    s0 = 0
    s1 = 0
    for a in al:
        b = (a>>mi)&1
        if b==1:
            s1 += 1
        else:
            s0 += 1
    cs.append((s0,s1))
    mi += 1
mi += 1

res = 0
for idx in range(mi):
    x = 0
    for i in range(mi):
        if i>idx:
            x += k&(1<<i)
        elif i==idx:
            pass
        else:
            if cs[i][0]>cs[i][1]:
                x += 1<<i
    if x<=k:
        res = max(res, f(x))

print(res)


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

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

    vector< int > deg(n * n);
    vector< vector< int > > to(n * n);
    for (int i = 0; i < 2 * n * n - 2 * n; ++i) {
        int a, b;
        cin >> a >> b;

        a--;
        b--;

        deg[a]++;
        deg[b]++;

        to[a].emplace_back(b);
        to[b].emplace_back(a);
    }

    int v;
    vector< vector< int > > ans(n, vector< int >(n, -1));
    vector< bool > used(n * n);

    int st;
    for (int i = 0; i < n * n; ++i) {
        if (deg[i] != 2) continue;
        st = i;
    }

    vector< int > dx({1, 0, -1, 0});
    vector< int > dy({0, 1, 0, -1});
    for (auto u: to[st]) {
        if (used[u]) continue;
        v = u;
    }

    used[st] = true;
    ans[0][0] = st;

    int pre = st;
    int x = 1, y = 0;
    int idx = 0;
    
    while (v != st) {
        ans[x][y] = v;
        used[v] = true;

        int next;
        for (auto u: to[v]) {
            if (u == pre) continue;
            if (deg[u] == 4) continue;
            next = u;
        }

        if (deg[v] == 2) idx++;
        pre = v;
        v = next;
        x += dx[idx];
        y += dy[idx];
    }

    for (int i = 0; i < n - 1; ++i) {
        for (int j = 1; j < n - 1; ++j) {
            int v = ans[i][j];
            for (auto u: to[v]) {
                if (used[u]) continue;
                ans[i + 1][j] = u;
                used[u] = true;
            }
        }
    }

    for (auto a: ans) {
        for (int i = 0; i < n; ++i) {
            cout << a[i] + 1 << (i + 1 == n ? '\n' : ' ');
        }
    }
}



Measured memory_bytes: 3628
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int[] s = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int cnt = 1;
            for (int i = 0; i < s.Length; i++)
            {
                int target = s[i];
                if (target == cnt)
                {
                    cnt++;
                }
            }
            if (cnt == 1)
            {
                WriteLine(-1);
            }else
                WriteLine(n-(cnt-1));
        }
    }
}

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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
 	int n, W;
 	cin >> n >> W;
 	vector<int> w(n), v(n);
 	for (int i = 0; i < n; i++) {
 		cin >> w[i] >> v[i];
 	}
 	int total_possible = 0;
 	for (int x : v) {
 		total_possible += x;
 	}
 	long long dp[n + 1][total_possible + 1];
 	for (int i = 0; i <= n ; i++) {
 		for (int j = 0; j <= total_possible; j++) {
 			if (j == 0) {
 				dp[i][j] = 0;
 			} else if (i == 0) {
 				dp[i][j] = INT_MAX;
 			} else {
 				dp[i][j] = dp[i - 1][j];
 				if (j >= v[i - 1]) {
 					dp[i][j] = min(dp[i][j], w[i - 1] + dp[i - 1][j - v[i - 1]]);
 				}
 			}
 		}
 	}
 	long long ans = 0;
 	for (int j = total_possible; j > 0; j--) {
 		for (int i = 1; i <= n; i++) {
 			if (dp[i][j] <= W) {
 				ans = j;
 				break;
 			}
 		}
 		if (ans != 0) {
 			break;
 		} 
 	}
 	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 79232
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readC(T...)(size_t n,ref T t){foreach(ref v;t)v=new typeof(v)(n);foreach(i;0..n){auto r=rdsp;foreach(ref v;t)pick(r,v[i]);}}

void main()
{
  int[] a; readC(5, a);
  int k; readV(k);
  writeln(a[4]-a[0] <= k ? "Yay!" : ":(");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define erep(i,a,b) for(int i=a;i<=(int)(b);i++)
#define per(i,a,b) for(int i=(b)-1;i>(a);i--)
#define eper(i,a,b) for(int i=((int)(a));i>=b;i--)
#define pb push_back
#define mp make_pair
#define INF (1<<30)-1
#define MOD 1000000007
using namespace std;
typedef long long ll;
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
int gcd(int a,int b){return b?gcd(b,a%b):a;}

string s, p;
int main() {
 ios::sync_with_stdio ( false );
 cin.tie ( 0 );
    cin >> s >> p;
    s += s;
    if (s.find(p) != -1) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3196
x = [0]*4
y = [0]*4
x[0], y[0], x[1], y[1] = map(int, input().split())

x[3] = x[0] - (y[1] - y[0])
y[3] = y[0] + (x[1] - x[0])

x[2] = x[1] + x[3] - x[0]
y[2] = y[1] + y[3] - y[0]

print(str(x[2]) + ' ' + str(y[2]) + ' ' + str(x[3]) + ' ' + str(y[3]))

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

int main() {
  int x;
  cin >> x;
  priority_queue<int> ans;
  ans.push(1);
  for (int i = 2; i <= sqrt(x); i++) {
    int p = 2;
    while (pow(i, p) <= x) {
      ans.push(pow(i, p));
      p++;
    }
  }
  cout << ans.top() << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;
vector<ll> nums;

bool check(ll k){
    ll cnt=0;
    rep(i,N){
        ll n = nums[i]+k-(N-1);
        if(n>0){
            cnt+=n/(N-1);
        }
    }
    return cnt<=k;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    nums.resize(N);
    rep(i,N) cin>>nums[i];
    
    ll cnt=0;
    while(true){
        ll sum=0;
        rep(i,N){
            if(nums[i]>=N){
                ll c = nums[i]/N;
                nums[i] -= c*(N+1);
                sum+=c;
            }
        }
        bool f=true;
        rep(i,N){
            nums[i]+=sum;
            if(nums[i]>=N) f=false;
        }
        cnt+=sum;
        if(f) break;
    }
    cout1(cnt);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int Maxn = 200000 + 100;
int N;
int A[Maxn], Next[Maxn], Pre[Maxn];
int main()
{
#ifdef hk_cnyali
	freopen("B.in", "r", stdin);
	freopen("B.out", "w", stdout);
#endif
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) scanf("%d", &A[i]);
	for (int i = 2; i <= N; ++i)
	{
		if (A[i - 1] < A[i])
		{
			Pre[i] = i - 1;
			continue;
		}
		else 
		{
			int now = i - 1;
			while (now && A[now] > A[i])
				now = Pre[now];
			Pre[i] = now;
		}
	}
	Next[N] = N + 1;
	for (int i = N - 1; i >= 1; --i)
	{
		if (A[i + 1] < A[i])
		{
			Next[i] = i + 1;
			continue;
		}
		else 
		{
			int now = i + 1;
			while (now && A[now] > A[i])
				now = Next[now];
			Next[i] = now;
		}
	}
	LL Ans = 0;
	for (int i = 1; i <= N; ++i)
		Ans += (LL)(1ll * A[i] * (i - Pre[i]) * (Next[i] - i));
	cout<<Ans<<endl;
	return 0;
}

Measured memory_bytes: 2560
import sys

tree={}
np = -1

home=0
tree[home]=[None, None, None]

def search(p, x):
    while p != None:
        tmp = tree[p]
        if tmp[0] == x: return True
        if x < tmp[0]:
            p = tmp[1]
        else:
            p = tmp[2]
    return False

def node(x):
    global np
    np += 1
    tree[np] = [x, None, None]
    return np

def insert(p, x):
    if p == None or np == -1: return node(x)
    tmp = tree[p]
    if x== tmp[0]: return p
    elif x<tmp[0]:
        tree[p][1]=insert(tmp[1],x)
    else:
        tree[p][2]=insert(tmp[2],x)
    return p

def preorder(p):
    if p == None: return []
    p1, p2 = tree[p][1:3]
    return [tree[p][0]] + preorder(p1) + preorder(p2)

def inorder(p):
    if p == None: return []
    p1, p2 = tree[p][1:3]
    return inorder(p1) + [tree[p][0]] +inorder(p2)

n = int(input())
i = 0
while i<n:
    s = raw_input()
    if s[0]=='i':
        insert(0,int(s[7:]))
    elif s[0]=='p':
        print ' ' + ' '.join(map(str, inorder(home)))
        print ' ' + ' '.join(map(str, preorder(home)))
    i += 1

Measured memory_bytes: 136692
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
    static FastScanner sc;

    public static void main(String[] args) {
        sc = new FastScanner();
        new Main().run();
    }

    private void run() {
        int N = sc.nextInt();
        String S = sc.next();

        int now = 0;
        int ans = 0;

        for (int i = 0; i < N; i++) {
            char c = S.charAt(i);
            if (c == 'I') {
                now++;
            } else {
                now--;
            }
            ans = Math.max(ans, now);
        }

        System.out.println(ans);
    }

}

/** 標準入力読み込み用クラス */
class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte())
            return buffer[ptr++];
        else
            return -1;
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr]))
            ptr++;
        return hasNextByte();
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext())
            throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

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


int read_p,read_ca;
inline int read(){
    read_p=0;read_ca=getchar();
    while(read_ca<'0'||read_ca>'9') read_ca=getchar();
    while(read_ca>='0'&&read_ca<='9') read_p=read_p*10+read_ca-48,read_ca=getchar();
    return read_p;
}
int t[110000],n,a;
int main(){
	n=read();
	for (int i=1;i<=n;i++){
		a=read();
		t[a]++;t[a+1]++;t[a+2]++;
	}
	a=0;
	for (int i=0;i<=100100;i++) if (t[i]>a) a=t[i];
	printf("%d\n",a);
}

Measured memory_bytes: 512
import java.util.*;

public class Main {
  public static void main(String... args) {
    Scanner scan = new Scanner(System.in);
    int A1 = scan.nextInt();
    int A2 = scan.nextInt();
    int A3 = scan.nextInt();
    int sum = A1 + A2 + A3;
    System.out.println(sum >= 22 ? "bust" : "win");
  }
}

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

int main() {

	int h, w, n; cin >> h >> w >> n;
	vector<int> color;
	for (int i = 0; i < n; i++) {
		int a; cin >> a;
		while (a--) {
			color.push_back(i + 1);
		}
	}
	vector<vector<int>> c(h, vector<int>(w));
	int index = 0;
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < w; j++) {
				c[i][j] = color[index];
				index++;
			}
		}
		else {
			for (int j = w - 1; j >= 0; j--) {
				c[i][j] = color[index];
				index++;
			}
		}
	}
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cout << c[i][j];
			if (j != w - 1) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
#include<iostream>
using namespace std;
int main()
{
  string lp;
  cin>>lp;
  if (lp=="SAT")
  {
    cout<<"1";
  }
  else if (lp=="SUN")
  {
    cout<<"7";
  }
 else if (lp=="MON")
  {
    cout<<"6";
  }
 else  if (lp=="TUE")
  {
    cout<<"5";
  }
 else if (lp=="WED")
  {
    cout<<"4";
  }
 else if (lp=="THU")
  {
    cout<<"3";
  }
else   if (lp=="FRI")
  {
    cout<<"2";
  }
  return 0;
}

Measured memory_bytes: 256
import Data.List

manyMedians :: Int -> [Int] -> IO ()
manyMedians n xs = mapM_ (\a -> if a < b1 then print b1 else print b2) xs
    where
        ys = sort $ xs
        (b1,b2) = (ys !! (n `div` 2), ys !! (n `div` 2 - 1))
        
main :: IO ()
main = do
    n <- read <$> getLine
    xs <- map read . words <$> getLine
    manyMedians n xs

Measured memory_bytes: 106876
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        FastReader sc = new FastReader();
        PrintWriter out = new PrintWriter(System.out);

        int n = sc.nextInt();
        int k = sc.nextInt();

        out.println(n-k+1);

        out.flush();
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                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());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

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

int main() {
  int N = 0; 
  cin >> N; 
  
  vector <int> a(N);
  for(int i = 0; i < N; i++){
    cin >> a.at(i);
  }
//  cout << a.at(0) << endl;
  
  int lighted = 1, count = 0;
  
  for(int i = 0; i < N; i++){
    if(lighted == 2){
//      cout << count << "a" << endl;
      cout << count << endl;
      break;
    }
    else if(count >= N-1){
//      cout << count << "b" << endl;
      cout << -1 << endl;
      break;
    }
    else{
      lighted = a.at(lighted - 1); 
      count++;
//      cout << count << "c" << endl;
    }
  }
}


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

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

	cin >> str;

	if (str.back() == 's') {
		str += "es";
	}
	else {
		str += 's';
	}

	cout << str << '\n';

	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n-1; i >= 0; i--)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using pii = pair<int, int>;
const int mod = 1e9+7;
const int INF = 1e9;
const int MAX = 1e6;
// const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// struct edge {int to, cost;};
// vector<edge> graph[MAX];
// bool visited[MAX];
// int dist[MAX];

int main() {
    // input
    int n, q;
    cin >> n >> q;
    int a[n];
    fenwick_tree<ll> fw(n);
    rep(i, n) {
        cin >> a[i];
        fw.add(i, a[i]);
    }
    // solve
    rep(i, q) {
        int t, x, y;
        cin >> t >> x >> y;
        if (t == 0) {
            fw.add(x, y);
        } else if (t == 1) {
            cout << fw.sum(x, y) << endl;
        }
    }
}

Measured memory_bytes: 10196
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
    int n,V[200],C[200],ans=0;
    cin>>n;
    rep(i,n) cin>>V[i];
    rep(i,n) cin>>C[i];
    rep(i,n){
        int a=V[i]-C[i];
        if(a>0) ans+=a;
    }
    cout<<ans;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

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

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

const int max_n = 10000000;
vector< bool > is_prime(max_n + 1, true);
vs32 primes;
int sieve(int n)
{
    if (n > max_n) return -1;
    is_prime[0] = is_prime[1] = false;
    for (s64 i = 2; i <= n; ++i)
    {
        if (is_prime[i])
        {
            primes.push_back(i);
            for (int j = i + i; j <= n; j += i) is_prime[j] = false;
        }
    }
    return primes.size();
}

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

    s64 n;
    cin >> n;

    sieve(n);

    s64 ans = 0;
    vs64 f(n + 1, 0);
    f[1] = 1;
    for (s64 i = 2; i <= n; ++i)
    {
        if (is_prime[i])
        {
            f[i] = 2;
        }
        else
        {
            for (auto prime : primes)
            {
                if (i % prime == 0)
                {
                    int temp = 0;
                    int j = i;
                    while (j % prime == 0)
                    {
                        ++temp;
                        j /= prime;
                    }
                    f[i] = f[j] * (temp + 1);
                    break;
                }
            }
        }
        // cout << i << ": " << f[i] << "\n";
    }

    for (s64 k = 1; k <= n; ++k)
    {
        ans += k * f[k];
    }

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



Measured memory_bytes: 85384
import fractions as fr

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

a.append(y)

ans=abs(a[0]-a[1])

for i in range(2,x+1):
	ans=fr.gcd(ans,abs(a[i]-a[i-1]))
print(ans)

Measured memory_bytes: 16244