akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < int(n); i++)
#define FOR(i,n,m) for(int i = int(n); i < int(m); i++)
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const int INF = 1e9 + 6;
const ll LLINF = 1e18 + 1;

struct DAG {
private:
    struct Edge {
        int to;
    };
    std::vector<std::vector<Edge>> graph;
    bool is_dag = false;
    std::vector<int> sorted; // トポロジカルソート
    int V; // 頂点数
public:

    DAG(int v) {
        assert(v > 0);
        V = v;
        graph.resize(v);
    }

    // from から to への有向辺を張る
    void add_edge(int from, int to) {
        graph[from].push_back({to});
    }

    // トポロジカルソート O(V + E)
    // DAG じゃないなら size 0 の vectorを返す
    std::vector<int> topological_sort() {
        std::stack<int> sta;
        //std::vector<int> dist(V, 0);//その頂点までの最長路
        std::vector<int> in(V, 0);// 入次数
        int used_cnt = 0;//使用した頂点の数
        for (int i = 0; i < V; i++) {
            for (Edge e : graph[i]) {
                in[e.to]++;
            }
        }
        for (int i = 0; i < V; i++) if (in[i] == 0) {
            sta.push(i);
            used_cnt++;
        }
        while (!sta.empty()) {
            int p = sta.top(); sta.pop();
            sorted.push_back(p);
            for (Edge e : graph[p]) {
                int v = e.to;
                in[v]--;
                //dist[v] = std::max(dist[v], dist[p] + 1);
                if (in[v] == 0) {
                    sta.push(v);
                    used_cnt++;
                }
            }
        }
        if (used_cnt == V) {
            return sorted;
        }
        else {
            return std::vector<int>(0);
        }
    }

    vector<Edge>& operator[](int x) {
        return graph[x];
    }
};

int main() {
    int v, e; cin >> v >> e;
    DAG G(v);
    REP(i, e) {
        int s, t; scanf("%d %d", &s, &t);
        G.add_edge(s, t);
    }
    if (G.topological_sort().size() == 0) {
        puts("1");
    }
    else {
        puts("0");
    }
    return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
int a,b,r;
string s;
int main(){
	cin>>a>>b;
	for(int i=a;i<=b;i++){
		ostringstream ss;
		ss<<i;
		s=ss.str();
		if(s[0]==s[4]&&s[1]==s[3]) r++;
	}
	cout<<r<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int len =Integer.parseInt(sc.nextLine());
		int[] line = Stream.of(sc.nextLine().split(" ", 0)).mapToInt(Integer::parseInt).toArray();
		int ans=0;
		Arrays.sort(line);

		ans = line[len / 2] - line[len / 2 - 1];



		System.out.println(ans);
	}
}


Measured memory_bytes: 54616
#include<stdio.h>
#define N 101

int main()
{
  int i,j,k,l,x;
  int n,p[N],M[N][N];
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++)
    {
      scanf("%d%d",&p[i-1],&p[i]);
    }

  for(i=1;i<=n;i++) M[i][i]=0;
  for(l=2;l<=n;l++)
    {
      for(i=0;i<=n-l+1;i++)
	{
	  j=i+l-1;
	  M[i][j]=99999;
	  for(k=i;k<=j-1;k++)
	    {
	      x=M[i][k]+M[k+1][j]+p[i-1]*p[k]*p[j];
	      if(x<M[i][j]) M[i][j]=x;
	    }
	}
    }
  
  printf("%d\n",M[1][n]);

  return 0;
}



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

using namespace std;

typedef long long ll;

const double pi = 3.14159265358979323846;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define mod 1000000007LL
#define PS(p) cout << setprecision(15) << fixed << p << endl;
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
#define ALL(c) c.begin(), c.end()
#define CIN(v) cin >> v;
#define COUT(v) cout << v << endl;

ll memo[10000];

int main() {
  ll N;

  CIN(N);
  ll H[N];

  ll m = 0;
  ll last;
  CIN(last);
  ll c = 0;
  for (ll i = 1; i < N; i++) {
    CIN(H[i]);

    if (last >= H[i]) {
      c++;
    } else {
      m = max(c, m);
      c = 0;
    }

    last = H[i];
  }
  m = max(c, m);

  COUT(m);

  return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <unordered_map>

using namespace std;

typedef pair<long long int, long long int> P;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int DP[1100000] = {};

int main(){
    long long int N, D, H;
    cin >> N >> H >> D;
    long long int factN = 1, factS = 0;
    for(int i = 1; i <= N; i++){
        factN *= i;
        factN %= MOD;
        factS += factN;
        factS %= MOD;
    }
    DP[0] = factN;
    long long int S = factN;
    for(int i = 1; i < D; i++){
        DP[i] = S * factS % MOD;
        S += DP[i];
        S %= MOD;
    }
    for(int i = D; i < H; i++){
        DP[i] = S * factS % MOD;
        S += DP[i];
        S -= DP[i - D];
        S += MOD;
        S %= MOD;
    }
    cout << S << endl;
    return 0;
}

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

using namespace std;

const int MAX = 52;
long long n, x;
vector<long long> sz(MAX);
long long dp[MAX];

long long calc(long long n, long long x)
{
    if (x < 0) return 0;
    if (n == 0) return 1;
    if (x == 0) return 0;
    if (x+1 >= sz[n] && dp[n]) return dp[n];
    long long an = calc(n-1, x-1);
    if (x >= sz[n]/2) {
        an++;
        if (x > sz[n]/2)
            an += calc(n-1, x-sz[n]/2-1);
    }
    return an;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> x;
    x--;
    dp[0] = sz[0] = 1;
    for (int i = 1; i < MAX; ++i) {
        sz[i] = sz[i-1] * 2 + 3;
        dp[i] = dp[i-1] * 2 + 1;
    }
    cout << calc(n, x) << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import deque

n, q = map(int, input().split())
name_time = [input().split() for _ in range(n)]

d = deque()
d.extend(name_time)

total_time = 0

while d:
    name, time = d.popleft()
    time = int(time)
    if time <= q:
        total_time += time
        print(name, total_time)
    else:
        total_time += q
        d.append([name, str(time-q)])


Measured memory_bytes: 19888
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;

using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

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

   if(n%2==0) cout<<n/2-1 <<endl;
   else cout<<n/2 <<endl;




    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int,int>
#define PIII pair<int,pii>
#define PLL pair<ll,ll>
#define PLII pair<ll,pii>
#define VI vector<int>
#define FF first
#define SS second
#define MP make_pair
#define PB push_back
#define MX 100001
#define EPS 0.00000000001
#define MOD 1000000007
#define PI acos(-1)
#define INF 100000000
#define loop(i,b,n) for(int i=b;i<n;++i)
#define rev_loop(i,b,n) for(int i=b;i>=n;--i)
using namespace std;

int main()
{
    int a[3][3],v[3][3]={0};
    loop(i,0,3) loop(j,0,3) cin>>a[i][j];

    int n,b;
    cin>>n;
    loop(i,0,n)
    {
        cin>>b;
        loop(i,0,3) loop(j,0,3) if(a[i][j]==b) {v[i][j] = 1; break;}
    }

    int f = 0;

    loop(i,0,3) if(v[i][0]&& v[i][1]&& v[i][2]) {f=1;}
    loop(i,0,3) if(v[0][i] && v[1][i] && v[2][i]) {f=1;}
    if(v[0][0] && v[1][1] && v[2][2]) f=1;
    if(v[0][2] && v[1][1] && v[2][0]) f=1;

    if(f) cout<<"Yes\n";
    else cout<<"No\n";

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define x first
#define y second
#define size(a) (ll)(a).size()

typedef long long ll;
typedef long double ld;

using namespace std;
int n;
string s;

const ll MOD = 1e9 + 7;

int main()
{
    //ifstream cin("input.txt");
    //ofstream cout("output.txt");


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

    cin >> n;

    vector<ll> Dp(n + 1, 0);

    Dp[0] = 1;
    for (ll i = 1; i <= n; ++i) {
        for (ll j = 3; j <= i; ++j) {
            Dp[i] += Dp[i - j];
            Dp[i] %= MOD;
        }
    }

    cout << Dp[n];

}


Measured memory_bytes: 3660
(defmacro defsolver (name vars &body body)
  `(defun ,name ()
     (let (,@(mapcar #'list
            vars
            (mapcar (constantly '(read))
                vars)))
       ,@body)))

(defsolver solution-a ()
  (let* ((l (loop repeat 4 collect
		 (read-char))))
    (format t "~:[No~;Yes~]"
	    (and
	     (not
	      (and
	       (eql (nth 0 l) (nth 1 l))
	       (eql (nth 2 l) (nth 1 l))
	       (eql (nth 3 l) (nth 1 l))))
	     (or
	      (and
	       (eql (nth 0 l) (nth 1 l))
	       (eql (nth 2 l) (nth 3 l)))
	      (and
	       (eql (nth 0 l) (nth 2 l))
	       (eql (nth 1 l) (nth 3 l)))
	      (and
	       (eql (nth 0 l) (nth 3 l))
	       (eql (nth 1 l) (nth 2 l))))))))

(solution-a)

Measured memory_bytes: 14948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//初めにXをあり得る全通り試し、配列aの各々の要素についてXに出来るならXにし、Xに出来る要素の個数をカウント
//Xに出来る要素はXから+-1の範囲にある数
//i番目の要素が、配列aの要素がiであるものの個数であるような配列bを作ると、b[i=X-1]~b[i=X+1]の要素の和がX化できる要素の個数となる
//その個数のmaxを求める。
int main() {
 int N;
 cin >> N;
 vector<int> a(N);
 for(int i = 0;i<N;i++){
	 cin >> a[i];
 }
 
 sort(a.begin(),a.end());
 int aMax = a[N-1];
 int aMin = a[0];
 vector<int> b(aMax+1);
 
 a.push_back(-1);
 int c = 1;//aの各要素の個数
 for(int i = 0;i<N;i++){
	 if(a[i] == a[i+1]){
		 c++;
	 }
	 if(a[i] != a[i+1]){
		 b[a[i]] = c;
		 c = 1;
	 }
 }
 
  b.push_back(0);
  int ans = 0;

  
 for(int X = aMin;X <= aMax;X++){
   ans = max(ans,b[X-1] + b[X] + b[X+1]);
 } 
 cout << ans << endl;
  
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(){
  int n,k;
  scanf("%d%d\n",&n,&k);
  char s;
  for(int i = 0; i < n; ++i){
    scanf("%c",&s);
    if(i == k-1) s = s - 'A' + 'a';
    printf("%c",s);
  }
  printf("\n");
  return 0;
}

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rept(i,k,n) for(int i = (k); i < (int)(n); i++)
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())
#define X first
#define Y second

typedef long long ll;
typedef pair<double,double> Pdd;
typedef pair<int,int> Pii;

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号
    vector<int> siz; 

    UnionFind(int N) : par(N), siz(N,1) { //全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]); //根に行くまでに辿ったノードを根に直接付け替える
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        if (siz[rx] < siz[ry]) swap(rx, ry); //小を大にくっつける
        siz[rx] += siz[ry];
        par[ry] = rx;
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x){ // 素集合のサイズ
        return siz[root(x)];
    }
};

int main(){
    int cnt=0;
    while(true){
        int n,t,k;
        cin>>n>>t>>k;
        cnt++;
        if(n+t+k==0) return 0;
        vector<vector<int>> edge(n-1,vector<int>(3));
        int cost=0;
        rep(i,n-1){
            cin>>edge[i][0]>>edge[i][1]>>edge[i][2];
            edge[i][0]--; edge[i][1]--;
            cost += edge[i][2];
        }
        vector<bool> bs(n,false);
        rep(i,t){
            int a;
            cin>>a;
            bs[a-1]=true;
        }
        sort(edge.begin(), edge.end(), [](vector<int> a, vector<int> b) { return a[2] > b[2]; });
       // rep(i,n-1) cout<<edge[i][0]<<edge[i][1]<<edge[i][2]<<endl;
       UnionFind uf(n);
       int cut = t-1-k;
       for(auto eg: edge){
            int r1 = uf.root(eg[0]), r2 = uf.root(eg[1]);
            if(bs[r1] && bs[r2] && cut==0) continue;
            if(bs[r1] && bs[r2]) cut--;
            uf.unite(r1,r2);
            cost-=eg[2];
            bool bs1=bs[r1], bs2=bs[r2];
            bs[r1] = bs[r1] || bs2;
            bs[r2] = bs[r2] || bs1;
       }
       cout << "Case " << cnt << ": " << cost << endl;
    }
    return 0;
}


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

using namespace std ;

int n , m ;
vector< vector< int > > graph ;
int dp[ 100001 ] ;
bool visited[ 100001 ] ;

int dfs( int s )
{
    visited[ s ] = 1 ;
    int ans = 0 ;

    for( auto i : graph[ s ] )
        if( visited[ i ] )
            ans = max( ans , 1 + dp[ i ] )  ;
        else
            ans = max( ans , 1 + dfs( i ) ) ;

    dp[ s ] = ans ;
    return dp[ s ] ;
}
void solve()
{
    memset( dp , 0 , sizeof(dp) ) ;
    fill( visited , visited + n + 1 , 0 ) ;

    for( int i = 1 ; i <= n ; i++ )
        if( !visited[ i ] )
        {
            int dist = dfs( i ) ;
            dp[ i ] = dist ;
        }

    int maxx = 0 ;
    for( int i = 1 ; i <= n ; i++ )
        maxx = max( maxx , dp[ i ] ) ;
    cout << maxx << endl ;
}
int main()
{
    cin >> n >> m ;
    graph.resize( n + 1 ) ;

    for( int i = 0 ; i < m ; i++ )
    {
        int x , y ;
        cin >> x >> y ;

        graph[ x ].push_back( y ) ;
    }

    solve() ;
}


Measured memory_bytes: 11748
using System;
class Triple_Dots
    {
        static void Main(string[] args)
        {
            int input = int.Parse(Console.ReadLine());
            var str = Console.ReadLine();
            int length = str.Length;
            string output="";

            if (input >= length)
            {
                Console.WriteLine(str);
            }
            else
            {
                for(int i = 0; i < input; i++)
                {
                    output += str[i];
                }
                Console.WriteLine($"{output}...");
            }
        }
    }

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

typedef struct {
  char mark;
  int value;
} data;

void BubbleSort(data*, int);
void SelectionSort(data*, int);
int StableJudge(data*, data*, int*, int);
/*
  StableJudge
    return  0 -> Not Stable
            1 -> Stable
*/

void BubbleSort(data *C, int N) {
  int i,j;
  data temp;

  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(C[j].value < C[j-1].value){
        temp = C[j];
        C[j] = C[j-1];
        C[j-1] = temp;
      }
    }
  }
}

void SelectionSort(data *C, int N){
  int i, j, minj;
  data temp;

  for(i=0;i<N;i++){
    minj = i;
    for(j=i;j<N;j++){
      if(C[j].value < C[minj].value){
        minj = j;
      }
    }
    if(C[i].value != C[minj].value){
      temp = C[i];
      C[i] = C[minj];
      C[minj] = temp;
    }
  }
}

int StableJudge(data *C, data *C_sort, int *list, int N){
  int i, j, n;
  int *mark_C, *mark_C_sort;
  int flag = 0; //is it necessary to free()?

  for(i=0;i<9;i++){
    //printf("Loop %d\n",i);
    // If there is the same number
    if(list[i] > 1){
      flag = 1;

      mark_C = (int *)malloc(sizeof(int) * list[i]);
      n = 0;
      for(j=0;j<N;j++){
        if(C[j].value == i+1){
          mark_C[n] = j;
          n++;
        }
        if(n == list[i]) break;
      }
      //for(j=0;j<n;j++) printf("mark_C[%d] = %d\n",j,mark_C[j]);

      mark_C_sort = (int *)malloc(sizeof(int) * list[i]);
      n = 0;
      for(j=0;j<N;j++){
        if(C_sort[j].value == i+1){
          mark_C_sort[n] = j;
          n++;
        }
        if(n == list[i]) break;
      }
      //for(j=0;j<n;j++) printf("mark_C_sort[%d] = %d\n",j,mark_C_sort[j]);

      for(j=0;j<n;j++){
        //printf("%c  %c\n",C[mark_C[j]].mark,C_sort[mark_C_sort[j]].mark);
        if(C[mark_C[j]].mark != C_sort[mark_C_sort[j]].mark) {
          return 0;
        }
      }
    }
  }
  if(flag){
    free(mark_C);
    free(mark_C_sort);
  }
  return 1;
}

int main(){
  int N, i;
  char inp[3];
  data *C, *C_bub, *C_sel;
  // to judge same number
  int list[9] = {0,0,0,0,0,0,0,0,0};

  // data set
  scanf("%d",&N);

  C = (data *)malloc(sizeof(data) * N);
  C_bub = (data *)malloc(sizeof(data) * N);
  C_sel = (data *)malloc(sizeof(data) * N);

  for(i=0;i<N;i++){
    scanf("%s",inp);
    C[i].mark = C_bub[i].mark = C_sel[i].mark = inp[0];
    C[i].value = C_bub[i].value = C_sel[i].value = atoi(&inp[1]);
  }

  // get same number list
  for(i=0;i<N;i++){
    list[C[i].value-1]++;
  }
  //for(i=0;i<9;i++)  printf("list[%d] = %d\n",i,list[i]);


  // sort
  BubbleSort(C_bub, N);
  SelectionSort(C_sel, N);

  // print
  for(i=0;i<N;i++){
      printf("%c%d",C_bub[i].mark ,C_bub[i].value);
      if(i != N-1) printf(" ");
      else printf("\n");
  }
  if(StableJudge(C, C_bub, list, N)){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  for(i=0;i<N;i++){
      printf("%c%d",C_sel[i].mark ,C_sel[i].value);
      if(i != N-1) printf(" ");
      else printf("\n");
  }
  if(StableJudge(C, C_sel, list, N)){
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

  return 0;
}



Measured memory_bytes: 2128
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define Max(x,y,z) max(x,max(y,z))
#define Min(x,y,z) min(x,min(y,z))
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<long long, long long> pll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll,ll> ii;
typedef vector<pair<ll,ll> > vii;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<pair<long long,long long> > vpll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef pair<ll,pair<ll,ll> > iii;
#define PI 3.141592653589793
#define mod (ll)(1000*1000*1000+7)
//# define N 300005
template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); }
template<typename T> T pow(T a,T b, ll m){T ans=1; while(b>0){ if(b%2==1) ans=((ans%m)*(a%m))%m; b/=2; a=((a%m)*(a%m))%m; } return ans%m; }
# define INF (ll)1e18
# define LN 20  
typedef pair<ll,pair<ll,ll> > pii;
# define INF1 (int)1e9+2
# define maxn 100006
# define offset 1005

/*************************************************
struct Coupon {
    ll l;
    ll r;
    ll id;

    Coupon(ll l, ll r, ll id): l(l), r(r), id(id) {} // Initialization

    bool operator<(const Coupon& c) { // Sorting
        return l < c.l;    
    }
};

**************************************************/

ll dp[3005];

int main()
{
  ll n,k;
  cin >> n >> k;
  ll ans=0;
  vi v;
  for(ll i=1;i*i<=n;i++)
  {
     if(n%i==0)
     {
        v.pb(i);
        if((n/i)!=i)
           v.pb(n/i);

     } 
  }

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

  for(int i=0;i<v.size();i++)
  {
    dp[i]=pow(k,(v[i]+1)/2,mod);
    for(int j=0;j<i;j++)
    {
       if(v[i]%v[j]==0)
         {
           dp[i]-=dp[j];
           dp[i]+=mod;
           dp[i]%=mod;
         }
    }
    if(v[i]&1)
     {
        ans=(ans+(dp[i]*v[i])%mod);
        ans%=mod;
     }
     else
     {
       ans=(ans+(dp[i]*(v[i]/2))%mod);
       ans%=mod;
     }

  }

  cout << ans;


}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define rando mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define fi first
#define se second
#define debug(x) cerr << " - " << #x << ": " << x << endl;
#define debugs(x, y) cerr << " - " << #x << ": " << x << " " << #y << ": " << y << endl;
#define debugii(x) cerr << " - " << #x << ": " << x.fi<<","<<x.se << endl;
#define sep() cerr << "--------------------" << endl;
#define all(x) (x).begin(),(x).end()
#define sz(x) (ll)x.size()
#define ld long double
#define ll long long
//#define int ll
#define ii pair<int,int>
#define v vector<int>
#define vii vector<ii>
#define vv vector<vector<int> >
#define mp make_pair
#define INF 1000000000
#define pb push_back
#define EPS 1e-9
const int MOD = 1000000007; // 998244353
int32_t main(){
	boost;
	int n;
	cin>>n;
	for (int i = 1; i*i <= n; ++i)
	{
		if(!(n%i)){
			if(i<1||i>9||(n/i)<1||(n/i)>9)continue;
			cout<<"Yes";return 0;
		}
	}
	cout<<"No";
	return 0;
}
//long long
//array bounds
//special cases
//binary search

Measured memory_bytes: 256
import math
N,D =map(int,input().split())

X = [list(map(int,input().split())) for _ in range(N)]


cnt=0
lenx=len(X)
leny=len(X[0])
for i in range(lenx):
   
    for j in range(i+1,lenx):
        suma=0
        for k in range(leny):
            suma+=(X[i][k]-X[j][k])**2
 
        if math.sqrt(suma)%1==0:
       
            cnt+=1
        
print(cnt)


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

#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

typedef complex<ld> cld;
typedef vector<cld> vc;

const int mod = 200003, MX = 4 * mod;
int n, a[MX], f[MX];
vc p(mod);

const ld pi = acos(ld(-1));
int rev[MX];
cld wlpw[MX];

void fft (vc& a, int n, bool inv) {
    for (int i = 0; i < n; i++ )
        if (i < rev[i])
            swap(a[i], a[rev[i]]);

    for (int len = 2; len <= n; len <<= 1) {
        ld ang = 2 * pi / len * (inv ? -1 : 1);
        cld wl (cos(ang), sin(ang));

        wlpw[0] = cld(1, 0);
        for (int i = 1; i < len / 2; i++)
            wlpw[i] = wlpw [i-1] * wl;
        
        cld t;
        int r, l;
        for (int i = 0; i < n; i += len) {
            for (int j = 0; j < len / 2; j++) {
                r = i + j + len / 2; l = i + j;
                t = a[r] * wlpw[j];
                a[r] = a[l] - t;
                a[l] += t ;
            }
        }
    }

    if (inv)
        for (int i = 0; i < n; i++)
            a[i] /= n;
}
 
void obtRev ( int n, int log_n ) {
    for (int i = 0; i < n; i++) {
        rev[i] = 0 ;
        for (int j = 0; j < log_n; j++)
            if (i & (1 << j))
                rev[i] |= 1 << (log_n - 1 - j) ;
    }
}

void sq (vc &a) {
    int n = 1, ln = 0;

    while (n < a.size())
        n *= 2, ln++;
    n *= 2, ln++;
    obtRev(n, ln);

    a.resize(n);

    fft(a, n, 0);

    for (int i = 0; i < n; i++)
        a[i] *= a[i];

    fft(a, n, 1);

    for (int i = 0; i < n; i++) {
        a[i].real(ll(a[i].real() + 0.5));
        a[i].imag(0);
    }
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	ll acu = 1;
	forn (i, mod - 1) {
		f[acu] = i;
		(acu *= 2) %= mod;
	}
	
	cin >> n;

	forn (i, n) {
		cin >> a[i];
		if (!a[i]) continue;
		p[f[a[i]]] += 1;
	}

	sq(p);

	forn (i, n) {
		if (!a[i]) continue;
		p[2 * f[a[i]]] -= 1;
	}

	ll res = 0;
	acu = 1;

	forn (i, p.size()) {
		res += (ll)p[i].real() / 2 * acu;
		(acu *= 2) %= mod;
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 31916
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define puts(x) cout << x << ' ';
#define putln(x) cout << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 100010;

vector <int> adj[MAX];

int dfs(int v) {

	int res = 0;

	vector <int> yui;

	for (int p : adj[v])
	{
		yui.pb(dfs(p));
	}

	sort(all(yui));
	reverse(all(yui));

	rep((int)adj[v].size(), i)
	{
		res = max(res, yui[i]+i+1);
	}

	return res;
}

void solve(void){
	int N;
	cin >> N;

	rep(N-1, i) {
		int a;
		cin >> a;
		adj[a-1].pb(i+1);
	}

	putln(dfs(0));

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 15104
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(a,b) for(int a=0;a<(b);++a)
#define REP1(i,n) for(int i=1;i<=(n);++i)
#define debug(x) cerr<<#x<<": "<<x<<'\n'
#define all(x) (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define isYES(x) printf("%s\n",(x) ? "YES" : "NO")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define isYes(x) printf("%s\n",(x) ? "Yes" : "No")
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define INF (1<<29)
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define X first
#define Y second
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;


template<class T=int>
T in(){T x;cin>>x;return (x);}
template<class T>
void print(T& x){cout<<x<<'\n';}

const int MOD =(int)1e9+7;
const int mod =(int)1e9+7;
const int MAX =510000;
ll fac[MAX],finv[MAX],inv[MAX];
void COMint(){
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(int i=2;i<MAX;i++){
        fac[i]=fac[i-1]*i%MOD;
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
        finv[i]=finv[i-1]*inv[i]%MOD;
    }
}
ll COM(int n,int k){
    if(n<k) return 0;
    if(n<0||k<0)return 0;
    return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}
ll gcd(ll a,ll b){
    if(b==0)return a;
    if(a>b){
        swap(a,b);
    }
    return gcd(a,b%a);
}
ll lcm(ll a,ll b){
    ll g;g=gcd(a,b);
    return a*b/g;
}
bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second < b.second;
    }else{
        return a.first < b.first;
    }
}

bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first){
        return a.first < b.first;
    }else{
        return a.second < b.second;
    }
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

ll RS(ll N,ll P,ll M){
    if(P==0){
        return 1;
    }else{
        if(P%2==0){
            ll t=RS(N,P/2,M);
            return t*t%M;
        }else{
            return N*RS(N,P-1,M)%M;
        }
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N=in();
    ll ans=0;
    REP1(i,N){
        if(i%3!=0&&i%5!=0)ans+=i;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3656
import numpy as np

n = int(input())
input_X = [[int(i) for i in input().split()] for i in range(n)]
X = np.array(input_X)

pre_t = 0
pre_x = 0
pre_y = 0
for i in range(n):
    x_move = abs(X[i][1] - pre_x)
    y_move = abs(X[i][2] - pre_y)
    xy_sum = x_move + y_move
    spend_time = X[i][0]-pre_t
    if xy_sum%2 == spend_time%2 and spend_time >= xy_sum:
        pre_t = X[i][0]
        pre_x = X[i][1]
        pre_y = X[i][2]
        if i+1 == n:
            print('Yes')
        else:
            continue
    else:
        print('No')
        break

Measured memory_bytes: 32460
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/math/common_factor_rt.hpp>
#define USE_MATH_DEFINES
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;

using namespace std;
// namespace mp = boost::multiprecision;
// namespace mt = boost::math
// using Bint = mp::cpp_int;

int n;
bool dp[30][3000];

void solve(int n, int a[]) {
    dp[0][0] = true;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = true;
        for (int j = 1; j <= 2000; j++) {
            if (dp[i - 1][j])
                dp[i][j] = true;
            else if (j >= a[i - 1] && dp[i - 1][j - a[i - 1]])
                dp[i][j] = true;
            else dp[i][j] = false;
        }
    }
}

int main() {
    rep(i, 3000) dp[0][i] = false;
    cin >> n;
    int a[n];
    rep(i, n) cin >> a[i];
    solve(n, a);
    int q, m;
    cin >> q;
    rep(i, q) {
        cin >> m;
        if (dp[n][m])
            cout << "yes" << endl;
        else
            cout << "no" << endl;
    }
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N, K;
    cin >> N >> K;
    string S;
    cin >> S;

    vector<ll> kazu;
    vector<ll> atai;
    for(int i=0;i<N;i++){
    	int j = i;
    	while(S[i] == S[j]) j++;
    	kazu.push_back(j-i);
    	atai.push_back(S[i] - '0');
    	i = j - 1;
    }
    //cout << kazu << endl;
    //cout << atai << endl;
    ll M = kazu.size();
    vector<ll> kazusum(M+1, 0);
    REP(i, M) kazusum[i+1] = kazu[i] + kazusum[i];
    //cout << kazusum << endl;
    ll res = -1;
    REP(i, M){
    	if(i == 0 && atai[0] == 0){
    		ll val = kazusum[min(M, i+2*K)] - kazusum[i];
    		res = max(res, val);
    	}
    	if(atai[i] == 1){
    		ll val = kazusum[min(M, i+2*K+1)] - kazusum[i];
    		res = max(res, val);
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 2892
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <tuple>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()
#define INF 999999999
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
typedef pair<LL, LL> LP;
typedef pair<int, P> PP;
typedef pair<LL, LP> LPP;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

/*************** using variables ***************/
int a, b;
int hyaku, gohyaku, sen;
/**********************************************/

int main(){
    while(cin >> a >> b, a && b){
        hyaku = 0; gohyaku = 0; sen = 0;
        int zan = b - a;
        while(zan != 0){
            if(zan - 1000 >= 0){
                zan -= 1000;
                sen++;
            }else if(zan - 500 >= 0){
                zan -= 500;
                gohyaku++;
            }else{
                zan -= 100;
                hyaku++;
            }
        }
        cout << hyaku << " " << gohyaku << " " << sen << endl;
    }

}

Measured memory_bytes: 3076
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) {
        try {
            // 標準入力
            InputStreamReader isr = new InputStreamReader(System.in);
            BufferedReader br = new BufferedReader(isr);
            String str[] = br.readLine().split(" ");
            int a = Integer.parseInt(str[0]);
            int b = Integer.parseInt(str[1]);
            int c = Integer.parseInt(str[2]);
            if (a == b + c || b == a + c || c == a + b) {
                System.out.println("Yes");
            } else {
                System.out.println("No");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

Measured memory_bytes: 21076
//Resting_Prince
#include<bits/stdc++.h>
#define ll long long int
#define ld long double
#define mod 1000000009
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define all(v) v.begin(),v.end()
#define rep(i,a,b)    for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;

int main()
{
    ios;
    ll n,w,i,j,k,l,o,p=0,a[105],b[105];
    ll dp[102055];
    cin>>n>>w;p=1;
    memset(dp,mod,sizeof(dp));dp[0]=0;
    rep(j,0,n-1)
    {
        cin>>a[j]>>b[j];
        repr(i,p,0)
        {   
            if(dp[i]<=w)
            dp[i+b[j]]=min(dp[i+b[j]],dp[i]+a[j]);//cout<<dp[i]+a[j]<<":";
        }
        p+=b[j];
    }o=0;
    rep(i,1,p)
    {   //cout<<dp[i];
        if(dp[i]<=w)
        o=i;
    }cout<<o;
    return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3
#define mod 1000000007

struct state{
  int u,v,S,d;
};
bool operator<(const state& a,const state& b){return a.d > b.d;}

int N,M;
int dist[50][50][1<<10];

int main(){
  while(1){
    cin>>N>>M;
    if(N==0)break;
    vector<P> g[N],rg[N];
    vector<int> A(N),F(N);
    A[0]=0; F[0]=0;
    A[N-1]=1000; F[N-1]=0;
    repl(i,1,N-1)cin>>F[i]>>A[i];
    rep(i,M){
      int a,b,c;
      cin>>a>>b>>c;
      a--;b--;
      g[a].push_back(P(b,c));
      rg[b].push_back(P(a,c));
    }
    
    vector<vector<int> > idx(1001);
    vector<int> ord(N);
    rep(i,N){
      ord[i]=idx[A[i]].size();
      idx[A[i]].push_back(i);
    }

    rep(i,N)rep(j,N)rep(S,1<<10)dist[i][j][S]=INF;
    priority_queue<state> que;
    que.push((state){0,0,1,0});
    while(que.size()){
      state s=que.top(); que.pop();
      if(dist[s.u][s.v][s.S]!=INF)continue;
      dist[s.u][s.v][s.S]=s.d;
      if(A[s.u]<A[s.v]){
        for(P e : g[s.u]){
          if(A[s.u]>A[e.fi])continue;
          if(A[e.fi]==A[s.v]){
            que.push((state){e.fi,s.v,(1<<ord[e.fi])|(1<<ord[s.v]),s.d+e.se+(e.fi!=s.v?F[e.fi]:0)});
          }else que.push((state){e.fi,s.v,0,s.d+e.se+F[e.fi]});
        }
      }else if(A[s.u]>A[s.v]){
        for(P e : rg[s.v]){
          if(A[s.v]>A[e.fi])continue;
          if(A[e.fi]==A[s.u]){
            que.push((state){s.u,e.fi,(1<<ord[e.fi])|(1<<ord[s.u]),s.d+e.se+(e.fi!=s.u?F[e.fi]:0)});
          }else que.push((state){s.u,e.fi,0,s.d+e.se+F[e.fi]});
        }
      }else{
        for(P e : g[s.u]){
          if(A[s.u]>A[e.fi])continue;
          if(A[e.fi]==A[s.v]){
            que.push((state){e.fi,s.v,s.S|(1<<ord[e.fi]),s.d+e.se+((s.S&(1<<ord[e.fi]))==0?F[e.fi]:0)});
          }else que.push((state){e.fi,s.v,0,s.d+e.se+F[e.fi]});
        }
        for(P e : rg[s.v]){
          if(A[s.v]>A[e.fi])continue;
          if(A[e.fi]==A[s.u]){
            que.push((state){s.u,e.fi,s.S|(1<<ord[e.fi]),s.d+e.se+((s.S&(1<<ord[e.fi]))==0?F[e.fi]:0)});
          }else que.push((state){s.u,e.fi,0,s.d+e.se+F[e.fi]});
        }
      }
    }

    if(dist[N-1][N-1][1]==INF)cout<<-1<<endl;
    else cout<<dist[N-1][N-1][1]<<endl;
  }
  return 0;
}



Measured memory_bytes: 78656
#include <bits/stdc++.h>
#define REP(i, N) for (int i = 0; i < (N); ++i)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }

//++時計回り --反時計回り
// int dx[4] = {1, 0, -1, 0};
// int dy[4] = {0, 1, 0, -1};
ll memo[101][4][4][4];

ll dfs(int length, int a, int b, int c, int n) {
  ll ret = 0;
  if (length == n) return 1;
  if (memo[length][a][b][c]) return memo[length][a][b][c];
  REP(d, 4) {
    if (b == 0 && c == 1 && d == 2) continue;
    if (b == 1 && c == 0 && d == 2) continue;
    if (b == 0 && c == 2 && d == 1) continue;
    if (a == 0 && b == 1 && d == 2) continue;
    if (a == 0 && c == 1 && d == 2) continue;
    ret += dfs(length + 1, b, c, d, n);
  }
  return memo[length][a][b][c] = ret % MOD;
}

int main() {
  int N;
  cin >> N;
  cout << dfs(0, 3, 3, 3, N) << '\n';
}


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

int main(){
	int N,K,ans=0;
	cin>>N>>K;
	
	int l[N];
	for(int i=0;i<N;i++)
		cin>>l[i];
	
	sort(l,l+N,greater<int>());
	
	for(int i=0;i<K;i++)
		ans+=l[i];
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K;cin>>K;bool F=false;
  for(int X=1,Y=7%K;X<K+2;X++,Y=((Y*10)+7)%K){
    if(Y==0){
      cout<<X<<endl;F=true;break;
    }
  }
  if(!F)cout<<-1<<endl;
}

Measured memory_bytes: 3608
#!/usr/bin/env python3
import sys

INF = 10**16

def solve(N: int, h: "List[int]"):

    dp = [INF]*(N)
    dp[0] = 0
    dp[1] = abs(h[1] - h[0])

    for i in range(2, N):
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]))

    print(dp[N - 1])
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    h = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, h)

if __name__ == '__main__':
    main()


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

using namespace std;

int main(){
    int n;
    cin>>n;
    int cur=0;
    for(int i=1;i<=1e6;i++){
        cur=10*cur+7;
        cur%=n;
        if(cur==0){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<"-1"<<endl;
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define Endl endl


signed main(void){
    int H,W;
    const int MEM=2019;
    char S[MEM][MEM];
    cin >> H >> W;
    REP(i,H){
        REP(j,W){
            cin >> S[i][j];
        }
    }
    
    int D[4][MEM][MEM]={};
    int now=-1;
    
    REP(k,4){
        REP(i,H){
            REP(j,W){
                D[k][i][j]=INF;
            }
        }
    }
    
    
    
    REP(i,H){
        now=-1;
        REP(j,W){
            if(S[i][j]=='#'){
                now=j;
                D[0][i][j]=0;
            }else{
                D[0][i][j]=min(D[0][i][j],abs(j-now));
            }
        }
    }
    
    REP(i,H){
        now=W;
        RREP(j,W){
            if(S[i][j]=='#'){
                now=j;
                D[1][i][j]=0;
            }else{
                D[1][i][j]=min(D[1][i][j],abs(j-now));
            }
        }
    }
    
    
    REP(j,W){
        now=-1;
        REP(i,H){
            if(S[i][j]=='#'){
                now=i;
                D[2][i][j]=0;
            }else{
                D[2][i][j]=min(D[2][i][j],abs(i-now));
            }
        }
    }
    
    REP(j,W){
        now=H;
        RREP(i,H){
            if(S[i][j]=='#'){
                now=i;
                D[3][i][j]=0;
            }else{
                D[3][i][j]=min(D[3][i][j],abs(i-now));
            }
        }
    }
    
    int Ans=0;
    int num=0;
    REP(i,H){
        REP(j,W){
            if(S[i][j]=='#')continue;
            num=1;
            REP(k,4){
                num+=max(D[k][i][j]-1,0LL);
            }
            Ans=max(Ans,num);
        }
    }
    /*REP(k,4){
        REP(i,H){
            REP(j,W){
                cout << D[k][i][j] << " ";
            }cout << endl;
        }cout << endl << endl;
    }*/
    
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 131584
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
# ---------標準入力時--------------
h,w=map(int,readline().split())
ch, cw=map(int,readline().split())
dh, dw=map(int,readline().split())
m=list(map(lambda x: list(x.decode()), readlines()))
# ---------標準入力時--------------
 
ad = [(-1,0), (0,-1), (1,0), (0,1)]
warp = [(-2, -2),(-2, -1),(-2, 0),(-2, 1),(-2, 2),
 (-1, -2),(-1, -1),(-1, 1),(-1, 2),
 (0, -2),(0, 2),
 (1, -2),(1, -1),(1, 1),(1, 2),
 (2, -2),(2, -1),(2, 0),(2, 1),(2, 2)]
 
def bfs6():
    '''
    bfs5から少し変更
    あるマス(i,j)から上(i-1,j)下(i+1,j) もしくは 左(i,j-1)右(i,j+1)に歩いて行ける時、
    (i,j)からwarpで行ける範囲は、その上下もしくは左右でカバーされるので、(i,jは考えなくていい)
    これをwarpを考えるときに処理する
    '''
    que1=[]
    que2=[] # queueというよりはメモリ
    m[ch][cw]=str(0)
    que1.append((ch,cw))
 
    while que1!=[]:
        l1=len(que1)
        r1=0 # que1における使用済みindex
 
        # que1の要素(座標)から歩いていけるマス
        while r1<l1:
            i, j=que1[r1]
            r1+=1
            for si, sj in ad:
                if m[i+si][j+sj]=='.': 
                    m[i+si][j+sj]=m[i][j]
                    que1.append((i+si, j+sj))
                    l1+=1
 
        # 歩いていけないマス
        for i,j in que1:
            if (m[i][j]==m[i-1][j] and m[i][j]==m[i+1][j]) or (m[i][j]==m[i][j-1] and m[i][j]==m[i][j+1]):
                continue
            for si, sj in warp:
                if m[i+si][j+sj]=='.':
                    m[i+si][j+sj]=str(int(m[i][j])+1)
                    que2.append((i+si, j+sj))
 
        que1=que2
        que2=[]
###---------------------------------------
 
for i in range(h):
    m[i] = ['#']*2 + m[i] + ['#']*2
    
m = [['#']*(w+4)]*2 + m + [['#']*(w+4)]*2
ch+=1; cw+=1; dh+=1; dw+=1
 
bfs6()
 
if m[dh][dw] == '.':
    print(-1)
else:
    print(m[dh][dw])

Measured memory_bytes: 29176
#include <iostream>
using namespace std;
#define repl(i, l, r) for (ll i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
using ll = long long;
const ll mod = 1e9 + 7;
int d[65][200005];
int main() {
	ll n, k;
	scanf("%lld%lld", &n, &k);
	int a[n];
	rep(i, n) {
		scanf("%d", &a[i]);
		a[i]--;
		d[0][i] = a[i];
	}
	rep(i, 64) {
		rep(j, n) { d[i + 1][j] = d[i][d[i][j]]; }
	}
	int now = 0;
	rep(i, 63) {
		if ((k >> i) & 1) { now = d[i][now]; }
	}
	printf("%d\n", now + 1);
	return 0;
}

Measured memory_bytes: 55388
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(long long i=0; i<(int)n; i++)
#define rep2(i,a,n) for(long long i=(a); i<(int)(n); i++)
#define all(vec) vec.begin(),vec.end()
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using psi = pair<string, int>;
const int dx[4] = {1, 0,-1, 0};
const int dy[4] = {0, 1, 0,-1};
const int mod = 1e9+7;
int gcd(int a, int b){if(a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int N, M, K, H, W, L, R, X, A, B, C;
//string S, T;

signed main(){
  cin >> A >> B;
  if(A==B) cout << "Draw" <<endl;
  else if(A==1 && B == 13) cout << "Alice" << endl;
  else if(A==13 && B == 1) cout << "Bob" << endl;
  else if(A>B)cout << "Alice" << endl;
  else cout << "Bob" << endl;
    
  return 0;
}

Measured memory_bytes: 3596
import sys
time_check = False
if time_check:
    import time

num_of_inversions = 0
array = [0 for x in range(200000)]

def merge(left, mid, right):
    n_fore = mid - left
    n_rear = right - mid
    l_fore = array[left:left + n_fore]
    l_fore.append(sys.maxsize)
    l_rear = array[mid:mid + n_rear]
    l_rear.append(sys.maxsize)

    i = j = 0
    global num_of_inversions

    offset = len(l_fore) - 1 + left
    for k in range(left, right):
        if l_fore[i] < l_rear[j]:
            array[k] = l_fore[i]
            i += 1
        else:
            array[k] = l_rear[j]
            num_of_inversions += j - k + offset
            #print(l_fore,l_rear, array[:23])
            #print(num_of_inversions,len(l_fore),len(l_rear),i,j,k)
            j += 1


def merge_sort(left, right):
    if left + 1 < right:
        mid = (left + right) // 2
        merge_sort(left, mid)
        merge_sort(mid, right)
        merge(left, mid, right)
    return


def main():

    n = int(input())
    for idx, value in enumerate(input().split()):
        array[idx] = int(value)

    if time_check:
        start = time.time()

    merge_sort(0, n)

    if time_check:
        print("elapsed_time:", time.time() - start)

    #print(" ".join(map(str, array[:n])))
    print(num_of_inversions)

    return


main()


Measured memory_bytes: 27724
while  line = gets
    n = line.chomp.split
    a = n[0].to_i
    b = n[2].to_i
    
    case n[1]
    when "+"
        puts a + b
    when "-"
        puts a - b
    when "/"
        puts a / b
    when "*"
        puts a * b
    else
        break
    end
end

Measured memory_bytes: 6876