akhauriyash/Code-Regression huggingface dataset:
//2020年4月17日現在

#include<stdio.h>
#include<cmath>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<complex>
#include<queue>
#include<set>
#include<utility>
#include<iomanip>
#include<limits>
#include<thread>
#include<map>
#include<stack>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_set>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<tuple>
#include <cstdio>

using namespace std;

template <class... A>
void prints() { cout << "\n"; }
template <class... A>
void prints_rest() { cout << "\n"; }
template <class T, class... A>
void prints_rest(const T &first, const A &... rest) { cout << " " << first; prints_rest(rest...); }
template <class T, class... A>
void prints(const T &first, const A &... rest) { cout << first; prints_rest(rest...); }
template <class T, class... A>
void printd(const T &first, const A &... rest) { cout << fixed << setprecision(15) << first; prints_rest(rest...); }


namespace {
    // printElems(&a[0], &a[n]);　みたいな感じで使う。
    void printElems(const int* begin, const int* end)
    {
        for (const int* p = begin; p != end; ++p) {
            std::cout << *p << ' ';
        }
        std::cout << std::endl;
    }
}

#define rep(i,n) for(int i=0; i<n; i++)
#define rep1(i,n) for(int i=1; i<n+1; i++)
#define repr(i,n) for(int i=n-1; i>=0; i--)
#define repr1(i,n) for(int i=n; i>0; i--)
#define FOR(i,j,n) for(int i=j; i < n; i++)
#define souatari(i,j,n) rep1(i,n-1)rep(j,i)
#define souatari1(i,j,n) for(int i=2; i<n+1; i++)rep1(j,i-1)
#define mp make_pair
#define F first
#define S second
#define elif else if

typedef long long ll;
typedef vector<int>  vi;
typedef vector<vi>  vvi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef array<int,3> arr3;
typedef long double D;


const ll llinf =  numeric_limits<ll>::max();
const ll _llinf = numeric_limits<ll>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const ll MOD = 1000000007;
const ll BIG = 1LL<<60;


ll dp[100005];
ll h[100005];

int main(){
	int n,k;
	cin >> n >> k;
	rep(i,n) cin >> h[i];
	rep1(i,n-1){
		ll anstmp = BIG;
		rep1(j,k){
			ll ori = max(0,i-j);
			anstmp = min(anstmp,abs(h[ori]-h[i])+dp[ori]);
		}
		dp[i] = anstmp;
	}

	prints(dp[n-1]);


	return 0;
}



Measured memory_bytes: 1792
from collections import defaultdict
from heapq import heappush, heappop, heapify, heapreplace
from random import randint

class Solution:
    def main(self):
        N, M = map(int, input().split())
        A = list(map(int, input().split()))
        # A = list(range(100000))
        A = sorted(A)
        BC = []
        for _ in range(M):
            b, c = map(int, input().split())
            BC.append((b, c))
        # BC *= 100000
        BC = sorted(BC, key=lambda x: -x[1])
        idx = 0
        for i in range(M):
            # print(A)
            b, c = BC[i]
            for j in range(b):
                if idx >= N or A[idx] >= c:
                    break
                else:
                    A[idx] = c
                    idx += 1

        print(sum(A))


if __name__ == '__main__':
    Solution().main()

Measured memory_bytes: 27212
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()   //reverse
#define strall(v) (v).cbegin(),(v).cend() //const_itterator
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
const long long INF = 1LL << 60;
//const int INF = 1e9+5;


int main(){
  int n,k;cin >> n >> k;
  vector<ll> h(n);
  rep(i,n) cin >> h[i];
  vector<ll> dp(n+100,INF);
  dp[0] = 0;
  for(int i=0;i<n;i++){
    for(int j=1;j<=k;j++){
      if(i+j >= n) break;
      //dp[i+j] = min(dp[i+j],dp[i] + abs(h[i+j]-h[i]));
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[n-1] << endl;
} 

Measured memory_bytes: 1792
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct dice{
    int face[6];
}dice;

void rotate(dice *d, char dir)
{
    int temp;
    switch(dir) {
    case 'N':
        temp=d->face[0];
        d->face[0]=d->face[1];
        d->face[1]=d->face[5];
        d->face[5]=d->face[4];
        d->face[4]=temp;
        break;
    case 'E':
        temp=d->face[0];
        d->face[0]=d->face[3];
        d->face[3]=d->face[5];
        d->face[5]=d->face[2];
        d->face[2]=temp;
        break;
    case 'W':
        temp=d->face[0];
        d->face[0]=d->face[2];
        d->face[2]=d->face[5];
        d->face[5]=d->face[3];
        d->face[3]=temp;
        break;
    case 'S':
        temp=d->face[0];
        d->face[0]=d->face[4];
        d->face[4]=d->face[5];
        d->face[5]=d->face[1];
        d->face[1]=temp;
        break;
    }
}

void rotateto(dice *d, int t, int f)
{
    static const char dir[]="NNNESSSWNNNESSSWNNNESSSW";
    int i;
    for(i=0; i<24; i++) {
        if(d->face[0]==t && d->face[1]==f) 
            return;
        rotate(d, dir[i]);
    }
}

int main()
{
    dice d;
    int i, n;
    for(i=0; i<6; i++) {
        scanf("%d", &d.face[i]);
    }
    scanf("%d", &n);
    int t, f;
    for(i=0; i<n; i++) {
        scanf("%d%d", &t, &f);
        rotateto(&d, t, f);
        printf("%d\n", d.face[2]);
    }
    return 0;
}

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

int main() {
    int n;cin>>n;
    int c[100001]{};
    ll sum=0;
    for (int i=0;i<n;i++) {
        int a;cin>>a;
        sum+=a;
        c[a]++;
    }
    int q;cin>>q;
    for (int i=0;i<q;i++) {
        int b,d;cin>>b>>d;
        sum+=(d-b)*c[b];
        cout<<sum<<endl;
        c[d]+=c[b];
        c[b]=0;
    }
    return 0;
}

Measured memory_bytes: 3908
#include<stdio.h>

int main(){
  long N,h,w,n;
  
  scanf("%ld",&N);
  
  for(h=1;h<=3500;h++){
    for(n=1;n<=3500;n++){
      if(4*n*h != N*(n+h)){
        if((h*n*N)/(4*h*n-N*(n+h)) >0 && (h*n*N)%(4*h*n-N*(n+h)) == 0){
          printf("%ld %ld %ld\n",h,n,((h*n*N)/(4*h*n-N*(n+h))));
          return 0;
        }
      }
    }
  }
  return 0;
}

Measured memory_bytes: 256
n = int(input())
ab=[]
for i in range(n):
    ab.append(list(map(int,input().split())))
sum = 0
ab.sort(key=lambda x:x[1])
for i in range(n):
    sum += ab[i][0]
    if sum>ab[i][1]:
        print("No")
        exit()
print("Yes")


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

#define ll long long
using namespace std;

int main()
{
    string s, t;
    cin >> s >> t;
    //cout << t.substr(0, s.size());
    if(t.substr(0, s.size()) == s) cout << "Yes";
    else cout <<"No";
}
/*

*/


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

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

    vector<int> s(m);
    vector<int> c(m);
    for(int i=0; i<m; i++){
        cin >> s.at(i) >> c.at(i);
    }

    vector<int> res(n, -1);
    for(int i=0; i<m; ++i){
        if(res.at(s.at(i)-1) != -1 && res.at(s.at(i)-1) != c.at(i) ){
            cout << -1;
            return 0;
        }

        res.at(s.at(i)-1) = c.at(i);
        if(n!= 1 && s.at(i) == 1 && c.at(i) == 0){
            cout << -1;
            return 0;
        }

        if(n==1 && s.at(i)==1 && c.at(i)==0){
            cout << 0;
            return 0;
        }
    }
    
    for(int i=0; i<pow(10, n); i++){
        bool flag = true;
        string str = to_string(i);
        if(str.length() != n) continue;
        for(int j=0; j<n; j++){
            if(!(res.at(j) == -1 || res.at(j) == str[j]-'0' )){
                flag = false;
                break;
            }
        }

        if(flag){
        cout << i;
        return 0;
        }
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int SelectionSort(int A[], int N){
  int cnt = 0;
  for(int i = 0; i < N; i++){
    int minj = i;

    for(int j = i; j < N; j++){
      if(A[j] < A[minj]){
        minj = j;
      }
    }

    swap(A[i],A[minj]);
    if(i != minj) cnt++;
  }
  return cnt;
}
int main(){
  int N,cnt;
  cin >> N;
  int A[N];
  for(int i = 0; i < N; i++)
    cin >> A[i];

  cnt = SelectionSort(A,N);

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

Measured memory_bytes: 1164
import sys
import itertools
import heapq
import numpy as np
stdin = sys.stdin
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

S=input()
print('ARC' if S=='ABC' else 'ABC')

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

int INF = 1e9;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> edge(n);
    vector<int> num(n, 0);
    int x, y;
    for (int i = 0; i < m; i++){
        cin >> x >> y;
        x--; y--;
        edge[x].push_back(y);
        num[y]++;
    }
    vector<int> ans(n, 0);
    queue<int> q;
    for (int i = 0; i < n; i++){
        if (num[i] == 0) q.push(i);
    }
    while (q.size()){
        x = q.front(); q.pop();
        for (int i = 0; i < edge[x].size(); i++){
            ans[edge[x][i]] = max(ans[edge[x][i]], ans[x] + 1);
            num[edge[x][i]]--;
            if (num[edge[x][i]] == 0) q.push(edge[x][i]);
        }
    }
    cout << *max_element(ans.begin(), ans.end()) << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#define fastIO ios::sync_with_stdio(NULL); cin.tie(NULL);

using namespace std;
const int N = 1E5+7;
const long long INF = 1E18;

long long f[N][4];
long long a[N], b[N], c[N];
int n;

int main()
{
    fastIO;
    cin>>n;
    
    for (int i = 1;i <= n;++i) cin>>a[i]>>b[i]>>c[i];
    
    for (int i = 0;i <= n;++i)
        for (int j = 1;j <= 3;++j) f[i][j] = -INF;
    
    long long tmp = 0;
    int save = 0;
    if (tmp < a[1]) { tmp = a[1]; save = 1; }
    if (tmp < b[1]) { tmp = b[1]; save = 2; }
    if (tmp < c[1]) { tmp = c[1]; save = 3; }
    
    f[1][save] = tmp;
    
    for (int i = 1;i <= n;++i)
        for (int j = 1;j <= 3;++j)
        {
            if (j == 1) f[i][j] = max(f[i][j],max(f[i-1][j+1]+a[i],f[i-1][j+2]+a[i]));
            if (j == 2) f[i][j] = max(f[i][j],max(f[i-1][j-1]+b[i],f[i-1][j+1]+b[i]));
            if (j == 3) f[i][j] = max(f[i][j],max(f[i-1][j-1]+c[i],f[i-1][j-2]+c[i]));
        }
    
    long long res = 0;
    for (int i = 1;i <= 3;++i) res = max(res,f[n][i]);
    
    cout<<res;
}

Measured memory_bytes: 9096
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
ll fac(ll a){
    ll ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
ll modinv(ll a,ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) {}

    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll a,b,c,d;cin >> a >> b >> c >> d;
    c-=a;
    d-=b;
    rep(i,c)cout << 'R';
    rep(i,d)cout << 'U';
    rep(i,c)cout << 'L';
    rep(i,d)cout << 'D';
    cout << 'D';
    rep(i,c+1)cout << 'R';
    rep(i,d+1)cout << 'U';
    cout << 'L';
    cout << 'U';
    rep(i,c+1)cout << 'L';
    rep(i,d+1)cout << 'D';
    cout << 'R' << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if(abs(a-c)<=d)cout<<"Yes";
	else if(abs(a-b)<=d && abs(b-c)<=d)
	cout<<"Yes";
	else
	cout<<"No";
	return 0; 
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n,i,m,count,flag,a[200];
  count=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    //printf("%d",a[i]);
  }
  while(1){
    flag=0;
    //printf("%d",flag);
    for(i=0;i<n;i++){
      //printf("a");
      if(a[i]%2==0){
        flag+=1;
        //printf("%d",flag);
      }
    }
    if(flag==n){
      count+=1;
      for(m=0;m<n;m++){
        a[m]=a[m]/2;
      }
    }
    else{
      break;
    }
  }
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main(void) {
    int L,i,a,b;
    a=0;
    scanf("%d" ,&L);
    for (i=1; i<=L; i++) {
        scanf("%d" ,&b);
        if (i%2==1 && b%2==1) {
            a++;
        }
    }
    printf("%d\n" ,a);
    return 0;
}

Measured memory_bytes: 1684
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

using namespace std;

#define forn(i, s, f) for (int i = s; i < f; i++)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()

vector <int> p, sz;

int get(int v) {
    if (p[v] == -1)
        return v;
    return p[v] = get(p[v]);
}

void unite(int v, int u) {
    v = get(v), u = get(u);
    if (v == u)
        return;
    if (sz[v] > sz[u])
        swap(v, u);
    p[v] = u;
    sz[u] += sz[v];
}

int main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector <int> a(n);
    forn (i, 0, n) 
        cin >> a[i], a[i]--;
    p.resize(n, -1), sz.resize(n);
    forn (i, 0, m) {
        int v, u;
        cin >> v >> u;
        v--, u--;
        unite(v, u);
    }
    int ans = 0;
    forn (i, 0, n)
        if (get(i) == get(a[i]))
            ans++;
    cout << ans;
    return 0;
}

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

int main() {
  int x, y ,z;
  cin >> x >> y >> z;

  cout << z << " " << x << " " << y << endl;

  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=list(map(int,input().split()))
visited={}
for i in range(1,n+1):
    visited[i]=-1
l=[1]
visited[1]=0
i=1
while True:
    if visited[a[l[i-1]-1]]==0:
        roop_start=l.index(a[l[i-1]-1])
        break
    visited[a[l[i-1]-1]]=0
    l.append(a[l[i-1]-1])
    i+=1
roop_dif=i-roop_start

if k<roop_start:
    print(l[k])
else:
    k-=roop_start
    k%=roop_dif
    print(l[roop_start+k])


Measured memory_bytes: 125172
def main():
    class UnionFind:
        def __init__(self, N):
            """
            N:要素数
            root:各要素の親要素の番号を格納するリスト.
                ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
            rank:ランク
            """
            self.N = N
            self.root = [-1] * N
            self.rank = [0] * N

        def find(self, x):
            """頂点xの根を見つける"""
            if self.root[x] < 0:
                return x
            else:
                while self.root[x] >= 0:
                    x = self.root[x]
                return x

        def union(self, x, y):
            """x,yが属する木をunion"""
            # 根を比較する
            # すでに同じ木に属していた場合は何もしない.
            # 違う木に属していた場合はrankを見てくっつける方を決める.
            # rankが同じ時はrankを1増やす
            x = self.find(x)
            y = self.find(y)
            if x == y:
                return
            elif self.rank[x] > self.rank[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] += 1

        def same(self, x, y):
            """xとyが同じグループに属するかどうか"""
            return self.find(x) == self.find(y)

    import sys
    n, q = map(int, sys.stdin.buffer.readline().split())
    uf = UnionFind(n)
    for i in range(q):
        t, u, v = map(int, input().split())
        if t:
            print(int(uf.same(u, v)))
        else:
            uf.union(u, v)


main()


Measured memory_bytes: 76876
def resolve():
    k, n = map(int, input().split())
    a = sorted([int(i) for i in input().split()])

    a_diff = [a[i] - a[i-1] for i in range(1, len(a))]
    a_diff.append((k - a[-1]) + a[0])
    a_diff = sorted(a_diff, reverse=True)

    print(sum(a_diff[1:]))


resolve()

Measured memory_bytes: 26444
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
int n,q,a,b,x[SZ];
ll f[SZ],tg=0;
const int M=262144;
struct ss
{
ll seg[SZ];
ss() {memset(seg,127/3,sizeof seg);}
ll qmin(int l,int r)
{
	ll s=1e18;
	for(l+=M-1,r+=M+1;l^r^1;l>>=1,r>>=1)
	{
		if(~l&1) s=min(s,seg[l^1]);
		if(r&1) s=min(s,seg[r^1]);
	}
	return s;
}
void upd(int x,ll y)
{
	x+=M; seg[x]=min(seg[x],y);
	for(x>>=1;x;x>>=1) seg[x]=min(seg[x+x],seg[x+x+1]);
}
}s1,s2;
void dbg()
{
	for(int i=1;i<=n;++i) cout<<s1.qmin(i,i)+i+tg<<" ";
	cout<<"\n";
}
int main()
{
	memset(f,127/3,sizeof f);
	scanf("%d%d%d%d",&n,&q,&a,&b);
	for(int i=1;i<=q;++i)
		scanf("%d",x+i);
	f[a]=min(f[a],(ll)abs(b-x[1]));
	f[b]=min(f[b],(ll)abs(a-x[1]));
	s1.upd(a,f[a]-a); s1.upd(b,f[b]-b);
	s2.upd(a,f[a]+a); s2.upd(b,f[b]+b);
	for(int i=2;i<=q;++i)
	{
		ll g=min(s1.qmin(1,x[i])+x[i],s2.qmin(x[i],n)-x[i])+tg;
		tg+=abs(x[i]-x[i-1]);
		s1.upd(x[i-1],g-x[i-1]-tg); s2.upd(x[i-1],g+x[i-1]-tg);
	}
	ll ans=1e18;
	for(int i=1;i<=n;++i)
		ans=min(ans,tg+s1.qmin(i,i)+i);
	printf("%lld\n",ans);
}


Measured memory_bytes: 16640
mod = 10**9+7
H, W = [int(i) for i in input().split()]
a = [input() for _ in range(H)]
dp = [[0]*W for _ in range(2)]
dp[0][0] = 1

for i in range(H):
    for j in range(W):
        if a[i][j] == '.':
            if i < H-1 and a[i+1][j] == ".":
                dp[1][j] = (dp[1][j] + dp[0][j]) % mod
            if j < W-1 and a[i][j+1] == ".":
                dp[0][j+1] = (dp[0][j+1] + dp[0][j]) % mod
    if i == H-1:
        break
    dp[0] = dp[1]
    dp[1] = [0]*W
print(dp[0][W-1])


Measured memory_bytes: 46316
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
using namespace std;
typedef long long ll;
int main() {
	string query;
	cin >> query;
	cin.ignore();
	vector<pair<int, string>> cn;
	map<string, string> obj;
	string buf;
	while (getline(cin, buf)) {
		int i = 0,j;
		for (; buf[i] == ' '; i++);
		if (buf.back() == ':') {
			if (i == 0) {
				cn.clear();
				cn.push_back(make_pair(i, ((string)".").append(buf.begin() + i, buf.end() - 1)));
				obj.insert(make_pair(cn.back().second,"*"));
			}
			else {
				while (cn.back().first >= i)cn.pop_back();
				cn.push_back(make_pair(i, cn.back().second + ((string)".").append(buf.begin() + i, buf.end() - 1)));
				obj.insert(make_pair(cn.back().second,"*"));
			}
		}
		else {
			for (j = i; buf[j] != ':'; j++);
			if (i == 0) {
				cn.clear();
				obj.insert(make_pair(((string)".").append(buf.begin() + i, buf.begin() +j), ((string)"").assign(buf.begin() + j+2, buf.end())));
			}
			else {
				while (cn.back().first >= i)cn.pop_back();
				obj.insert(make_pair(cn.back().second + ((string)".").append(buf.begin() + i, buf.begin()+j),((string)"").assign(buf.begin() + j+2, buf.end())));
			}
		}
	}
	auto res = obj[query];
	if (res=="")res = "no such property";
	else if(res == "*")res = "object";
	else res = "string \"" + res + "\"";
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3376
#include <iostream>
#include <cstdio>
#include <deque>
#include <vector>
#include <vector>
using namespace std;
const int maxn = 1e5 + 100;
vector<int> G[maxn];
int deep[maxn], sz[maxn], f[maxn];
deque<int> Q;
void dfs(int x, int fa, int d){
    deep[x] = d;
    sz[x] = 1;
    f[x] = fa;
    for(auto to : G[x]){
        if(to == fa) continue;
        dfs(to, x, d+1);
        sz[x] += sz[to];
    }
}

int main()
{
    int n, x, y;
    cin>>n;
    for(int i = 1; i < n; i++){
        scanf("%d %d", &x, &y);
        G[x].push_back(y);
        G[y].push_back(x);
    }
    dfs(1, 1, 1);
    x = n;
    while(x != 1){
        Q.push_back(x);
        x = f[x];
    }
    Q.push_back(1);
    int ansB = 0, ansW = 0, B = 0, W, temp;
    while(1){
        if(Q.empty()){
            ansB += sz[B]-1-sz[W];
            ansW = sz[W] - ansW;
            if(ansB <= ansW) cout<<"Snuke"<<endl;
            else cout<<"Fennec"<<endl;
            return 0;
        }
        temp = B;
        B = Q.back(); Q.pop_back();
        if(temp != 0) ansB += sz[temp]-sz[B]-1;
        if(Q.empty()) {
            ansB += sz[B]-1-sz[W];
            ansW = sz[W] - ansW;
            if(ansW <= ansB) cout<<"Fennec"<<endl;
            else cout<<"Snuke"<<endl;
            return 0;
        }
        W = Q.front(); Q.pop_front();
        ansW++;
    }
}


Measured memory_bytes: 15104
n = int(input())
l = []
ans = 0
for i in range(n):
    x = list(input().split())
    l.append(x)
for j in l:
    if j[1] == "JPY":
        ans += float(j[0])
    else:
        ans += float(j[0])*380000
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;


long long int n,ma,mb,a[45],b[45],c[45],num[250][250]={},num2[250][250]={};
long long int a2[45],b2[45],c2[45],atmp=0,btmp=0,costmp=0;
long long int sousa(long long int id,long long int pattern){
    if(pattern==1){     
    atmp+=a[id];
    btmp+=b[id];
    costmp+=c[id];
    }
    return 0;
}
//ビット全探索(n択m個)
void bit_tannsaku(long long int n,long long int m){
    long long int number[50]={1};
    for(int i=0;i<30;i++){
        number[i+1]=n*number[i];
    }
    for(int i=0;i<number[m];i++){
        atmp=0;
        btmp=0;
        costmp=0;
        for(int j=0;j<m;j++){
            long long int tmp=i;
            sousa(j,(tmp/number[j])%n);
        }
        num[atmp][btmp]=min(costmp,num[atmp][btmp]);
    }
}



long long int sousa2(long long int id,long long int pattern){
    if(pattern==1){     
    atmp+=a2[id];
    btmp+=b2[id];
    costmp+=c2[id];
    }
    return 0;
}
//ビット全探索(n択m個)
void bit_tannsaku2(long long int n,long long int m){
    long long int number[50]={1};
    for(int i=0;i<30;i++){
        number[i+1]=n*number[i];
    }
    for(int i=0;i<number[m];i++){
        atmp=0;
        btmp=0;
        costmp=0;
        for(int j=0;j<m;j++){
            long long int tmp=i;
            sousa2(j,(tmp/number[j])%n);
        }
        num2[atmp][btmp]=min(costmp,num2[atmp][btmp]);
        
    }
}






int main() {
	const long long int mod = 1000000007,INF=100000000000000;
	map<long long int, long long int>mp;
	cout << fixed << setprecision(10);
    typedef pair<long long int,long long int> P;
    priority_queue<P,vector<P>,greater<P>> que;
    P tmp;
    long long int res=INF;
    string str;
    for(int i=0;i<240;i++){
        for(int j=0;j<240;j++){
            num[i][j]=INF;
            num2[i][j]=INF;
        }
    }
    cin>>n>>ma>>mb;
    for(int i=0;i<n/2;i++){
        cin>>a[i]>>b[i]>>c[i];
        
    }
    for(int i=0;i<n-(n/2);i++){
        cin>>a2[i]>>b2[i]>>c2[i];
    }


    bit_tannsaku(2,n/2);
    bit_tannsaku2(2,n-n/2);

    for(int i=1;i<=200;i++){
        
         if(i*ma<=0||i*mb<=0||i*ma>200||i*mb>200){
           continue;
         }
        res=min(res,num[i*ma][i*mb]);
    }

     for(int i=1;i<=200;i++){
        
         if(i*ma<=0||i*mb<=0||i*ma>200||i*mb>200){
           continue;
         }
        res=min(res,num2[i*ma][i*mb]);
    }



    for(int i=0;i<=200;i++){
        for(int j=0;j<=200;j++){

            for(int k=1;k<=400;k++){
                if(k*ma-i<=0||k*mb-j<=0||k*ma-i>200||k*mb-j>200){
                    continue;
                }
                res=min(res,num[i][j]+num2[k*ma-i][k*mb-j]);
                if(num[i][j]+num2[k*ma-i][k*mb-j]<=100){
                }
            }




        }
    }
    if(res<INF){
        cout<<res<<endl;
    }else{
        cout<<-1<<endl;
    }
} 


Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    vector<ll>sum(n+1);
    sum[0]=0;
    REP(i,n)cin >> a[i];
    FORR(i,n-1,0)sum[n-i]=(sum[n-i-1]+a[i])%MOD;
    ll answer=0;
    REP(i,n){
        answer = (answer+(a[i]*sum[n-i-1])%MOD)%MOD;
    }
    cout << answer << endl;
    return 0;
}

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

int main() {
	
	int a, b;

	while (1) {
		cin >> a >> b;
		if (a == 0 && b == 0) break;
		else if (a > b) swap(a, b);
		cout << a << " " << b << endl;
	}

	return 0;
}


Measured memory_bytes: 3132
using System;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = ReadInts();

        Console.WriteLine((inputs[1] * 2 - 1) <= inputs[0] ? "YES" : "NO" );

    }

    public static string Read() { return Console.ReadLine(); }
    public static int ReadInt() { return int.Parse(Read()); }
    public static long ReadLong() { return long.Parse(Read()); }
    public static double ReadDouble() { return double.Parse(Read()); }

    public static string[] Reads() { return Console.ReadLine().Split(' '); }
    public static int[] ReadInts() { return Reads().Select(_ => int.Parse(_)).ToArray(); }
    public static double[] ReadDoubles() { return Reads().Select(_ => double.Parse(_)).ToArray(); }
}

Measured memory_bytes: 13396
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <limits.h>
#include <math.h>

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

using namespace std;

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

const int INF = INT_MAX;

int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int N,K,Q;
    cin >> N >> K >> Q;
    int A[2010];
    repeat(i, N) cin >> A[i];
    int ans = INF;
    repeat(x, N){
        int X = A[x];
        vector<int> c;
        multiset<int> s;
        repeat(i, N+1){
            if(i==N || A[i] < X){
                sort(c.begin(),c.end());
                repeat(j, (int)c.size()-K+1){
                    s.insert(c[j]);
                }
                c.clear();
            }else{
                c.push_back(A[i]);
            }
        }
        if(s.size() < Q)
            continue;
        auto it = s.begin();
        repeat(i, Q-1) it++;
        ans = min(ans,*it-X);
        //cout <<"X "<< X <<" Y "<< *it << " ans "<< ans << endl;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r,s;};
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX],H[MAX];

void print(int u){
 int i, c,child=0;
 if(T[u].l!=NIL)child++;
 if(T[u].r!=NIL)child++;

 printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", u, T[u].p, T[u].s, child,D[u],H[u]);

 if(T[u].p==NIL) printf("root");
 else if(T[u].l==NIL&&T[u].r==NIL) printf("leaf");
 else printf("internal node");

 printf("\n");

}

void calcDepth(int u, int p){
 D[u] = p;
 if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
 if(T[u].r!=NIL) calcDepth(T[u].r,p+1);
}

int calcHeight(int u){
    if(u==NIL)return -1;
    int left=calcHeight(T[u].l);
    int right=calcHeight(T[u].r);
    if(left>right)return H[u]=left+1;
    else return H[u]=right+1;
}

int main(){
 int i, left,right;
 int n;
 int id;
 int root = NIL;
 scanf("%d", &n);
 for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r =T[i].s= NIL;

 for(i=0; i<n; i++){
   scanf("%d %d %d", &id, &left,&right);
    if(left!=NIL){
        T[left].p = id;
        T[left].s=right;
        }
    if(right!=NIL){
        T[right].p = id;
        T[right].s=left;
        }
    T[id].l = left;
    T[id].r = right;

 }

 //根を求める (find the root)
 for(i=0; i<n; i++){
   if(T[i].p == -1) root = i;
 }

 //それぞれのノードの深さを求める (find depth of each node)
 calcDepth(root, 0);
 calcHeight(root);


 //出力 (output)
 for(i=0; i<n; i++) print(i);

 return 0;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b){ return a ? GCD(b % a, a) : b; }
int main(){
    ll n,k;
    cin>>n>>k;
    ll ans = 0;
    ll mod = 1e9+7;
    for(int i=k; i<=n+1; i++){
        ll tmp1=(n+(n-i+1LL))*i/2;
        ll tmp2=(i-1LL)*i/2;
        ans += tmp1-tmp2+1LL;
        ans %= mod;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define MAXN 110
#define int long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl '\n'
#define INF 1000000007
#define MAXV 100100
using namespace std;

	int w[MAXN];
	int v[MAXN];
	int dp[MAXN][MAXV]; 
	  	
int32_t main(){
int n,W;
cin>>n>>W;
int sum=0;
for(int i=1;i<=n;i++){
	cin>>w[i]>>v[i];
	sum+=v[i];
}

	for(int i=0;i<=n;i++)
		for(int j=0;j<=MAXV;j++)
			dp[i][j]=INF;
		
		dp[0][0]=0;
		dp[1][0]=0;
	for(int i=1;i<=n;i++)
	dp[i][v[i]]=w[i];
	
	 	
	for(int i=2;i<=n;i++)
		for(int j=0;j<=sum;j++){//mudar limites
			dp[i][j]=dp[i-1][j];
			if(j-v[i]>=0)dp[i][j]=min(dp[i][j],w[i]+dp[i-1][j-v[i]]);
		}
	
	int maxi=0;
	for(int j=MAXV;j>=0;j--){
	//	cout<<dp[n][j]<<endl;
		if(dp[n][j]<=W){
			maxi=j;
			break;
		}
	}
	cout<<maxi<<endl;   	
}

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please


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


	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int kotae = 0;
	rep1(i, 100) {
		if (A < i && i <= B && C < i && i <= D) kotae++;
	}

	co(kotae);

	Would you please return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int jj(int b,int p);
	int x,maxv=0;
	cin>>x;
	if(x==1){
		cout<<1;
		return 0;
	}
	for(int i=2;i<=int (sqrt(x));++i){
		for(int j=2;j<=10;++j){
			if(jj(i,j)<=x&&jj(i,j)>maxv)
				maxv=jj(i,j);
		}
	}	
	cout<<maxv;
	return 0;
}
int jj(int i,int j){
	int ans=1;
	for(int k=1;k<=j;k++){
		ans*=i; 
	}
	return ans;
}


Measured memory_bytes: 384
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
typedef long long LL;
template<class T> inline void chmax(T & a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

#define MOD 1000000007

int main(void) {
	int N, M, C;
	cin >> N >> M >> C;
	vector<int> B(M);
	rep(i, M) cin >> B[i];

	int count = 0;
	rep(i,N) {
		vector<int> A(M);
		rep(j,M) {
			cin >> A[j];
		}

		int sum = C;
		rep(j, M) {
			sum += B[j]*A[j];
		}

		if (sum > 0) {
			count++;
		}
	}
	cout << count << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
using namespace std;
typedef long long int ll;
constexpr int kMod = int(1E9 + 7);
int a[30][30];
ll dp[2][1 << 21];
int main() {
	int n;
	bool f = false;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) for (int j = 1; j <= n; j++) scanf("%d", &a[i][j]);
	dp[!f][0] = 1;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) if (a[i][j]) {
			for (int k = 0; k < (1 << n); k++) if ((1 << (j - 1)) & k) dp[f][k] += dp[!f][k ^ (1 << (j - 1))];
		}
		for (int j = 0; j < (1 << n); j++) dp[f][j] %= kMod;
		f = !f;
		memset(dp[f], 0, sizeof(dp[f]));
	}
	printf("%lld\n", dp[!f][(1 << n) - 1]);
}


Measured memory_bytes: 34496
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { cout << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);	
}

int main()
{
	ios_init();
	string s;
	while(cin >> s) {
		bool f = true;
		REP(i,SZ(s)-1){
			if(s[i] == 'A' and s[i+1] == 'C'){
				f = false;
			}
		}
		if(f){
			cout << "No" << endl;
		} else {
			cout << "Yes" << endl;
		}
	}
	return 0;
}


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

int main(){
    int N, Y;
    int sum = 0;
    int flag = 0;
    int I, J;
    cin >> N >> Y;

    for (int i = 0; i <= N; i++){
        for (int j = 0; j <= N - i; j++){
            sum = 1000 * i + 5000 * j + 10000 * (N - i - j);
            if (sum == Y){
                I = i;
                J = j;
                flag = 1;
                break;
            }
        }
    }
    if(flag){
        cout << N - I - J <<  " " << J << " " << I << endl;
    }else{
        cout << -1 << " " << -1 << " " << -1 << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <iterator>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <limits>
#include <iomanip>

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

inline int ctoi(char c) {
    return (int)(c -'0');
}

// ----------------------------------------------------------

ll f(ll n) {
    if (n == 0) {
        return 1;
    }
    return n * f(n - 2);
}

int main() {
    ll n;
    cin >> n;
    if (n % 2 == 1) {
        cout << "0" << endl;
        return 0;
    }
    ll ans = n / 10;
    ll five = 50;
    while (five <= n) {
        ans += n/ five;
        five *= 5;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n;
  cin >> n;
  ll ans = 0;
  rep2(i, 1, n+1){
    ll co = n/i;
    ans += co*(co+1)/2*i;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3576
n = gets.to_i
s = []
while g = gets
  s << g.chomp.split('').sort
end
# p s
arr = {}
s.each do |ss|
  arr[ss.join('')].nil? ? arr[ss.join('')]=1 : arr[ss.join('')]+=1
end
# p arr
# p s.group_by{|a|a}
p arr.map{|k,v|v==1 ? 0 : (1..(v-1)).inject(&:+)}
.inject(&:+)


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

a = [] 

[a.append(int(input()))  for i in range(n)]
a.sort()
    
#print (a)

ans = 0
i = 0

while(i<n):
    chk = a[i]
    tmp = 1
    while(i+tmp < n and chk == a[i+tmp]):
        tmp += 1
    ans += (tmp)%2
    i += tmp
print(ans)

Measured memory_bytes: 7884
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    long long a[n+5];
    for(int i=1;i<=n;i++)
    cin>>a[i];
    int visited[n+5];
    memset(visited,0,sizeof visited);
    int i=1;
    vector<int>v;
    int loc=0;
    while(true)
    {
        loc=a[i];
        if(visited[loc])
        break;
        else
        {
            v.push_back(loc);
            i=loc;
            visited[loc]=1;
        }
    }
    for(i=0;i<v.size();i++)
    {
        if(v[i]==loc)
        break;
    }
    int precycle=i;
  //  cout<<precycle<<'\n';
    if(k<=precycle)
    cout<<v[k-1];
    else
    {
        k-=precycle;
        int cycle=v.size()-i;
        k=k%cycle;
        if(k==0)
        k=k+cycle;
        k--;
        cout<<v[precycle+k];
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;

	int n;
	n = s.size();

	int ans = 0;
	for(int i = 0; i < n - i - 1; i++){
		if(s[i] != s[n - i - 1]) ans++;
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include<vector>
using namespace std;
int main()
{
	int i,j;
	scanf("%d%d",&i,&j);
	int k;
	k = i+j;
	
	if(i-j>k){
		k = i-j;
	}
	if(i*j>k){
		k = i*j;
	}
	printf("%d",k);
	

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.math.*;

public class Main {

  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    BigInteger total = new BigInteger("0");
    BigInteger square = new BigInteger("0");

    for (int i =0; i<N; i++) {
      long A = sc.nextLong();
      long AA = A * A;
      total = total.add(BigInteger.valueOf(A));
      square = square.add(BigInteger.valueOf(AA));
    }
    total = total.multiply(total);
    total = total.subtract(square);
    total = total.divide(BigInteger.valueOf(2));
    total = total.remainder(BigInteger.valueOf(1000000007));
    System.out.println(total);
  }
}

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

int main() {
	string s;
	cin >> s;
	vector<char>c(s.size() + 1);
	for (int i = 0; i < s.size(); i++) {
	    c[i] = s.at(i);
	}
	c[s.size()] = ' ';
	int j = 0, max = 0;
	for (int i = 0; i <= s.size(); i++) {
		if (c.at(i) == 'A' || c.at(i) == 'T' || c.at(i) == 'G' || c.at(i) == 'C') {
			j = i;
			int sum = 0;
			while (c.at(j) == 'A' || c.at(j) == 'T' || c.at(j) == 'G' || c.at(j) == 'C') {
			    if ((c.at(j) != 'A' && c.at(j) != 'T' && c.at(j) != 'G' && c.at(j) != 'C' )|| j == s.size()) break;
				sum++;
				j++;
				
			}
			if (sum > max) max = sum;
		}
	}
	cout << max << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

template<typename T> struct BIT {
	vector<T> bit;
	int n;
	
	BIT() {}
	BIT(int n) : bit(vector<T>(n + 2, 0)), n(n) {}
	
	T sum(int i) {
		i++;
		T s = 0;
		while (i > 0) {
			s += bit[i];
			i -= i & -i;
		}
		return s;
	}
	
	void add(int i, T x) {
		i++;
		while (i <= n) {
			bit[i] += x;
			i += i & -i;
		}
	}
};

int n, m;
vector<pii> svnir[112345];

int main() {
	cin >> n >> m;
	REP(i, n) {
		int l, r;
		scanf("%d %d", &l, &r);
		svnir[r - l + 1].push_back(pii(l, r));
	}
	
	BIT<int> bit(m + 2);
	
	for (int d = 1; d <= m; d++) {
		REP(i, svnir[d].size()) {
			bit.add(svnir[d][i].first, 1);
			bit.add(svnir[d][i].second + 1, -1);
		}
		n -= svnir[d].size();
		
		int ans = n;
		
		for (int pos = d; pos <= m; pos += d)
			ans += bit.sum(pos);
		
		printf("%d\n", ans);
	}
	return 0;
}

Measured memory_bytes: 8320
/*input
aba
4
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define MAX 
#define INF 0x3f3f3f3f

string s;
int k;
vector<string> sol;
int32_t main(){
	IOS;
	cin >> s >> k;
	REP(i , 0 , s.size()) REP(j , 1 , k + 1) sol.pb(s.substr(i , j));
	sort(ALL(sol));
	sol.resize(unique(ALL(sol)) - sol.begin());
	cout << sol[k - 1] << endl;
    return 0;
}

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

//cmdで g++ test.cpp とするとコンパイルできる

#define MOD 1000000007
typedef pair<int,int> pii;

int main() {
    int N,R;
    cin>>N>>R;
    if(N>=10){
        cout<<R<<endl;
    }else{
        cout<<R+100*(10-N)<<endl;
    }
}


Measured memory_bytes: 256
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.to_list @@ Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let dp = Array.make (k + 1) false in
  for i = 1 to k do
    dp.(i) <- not @@ List.for_all (fun a -> i - a < 0 || dp.(i - a)) as_
  done;
  print_endline @@
  if dp.(k) then "First" else "Second"


Measured memory_bytes: 5376
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
const double pi = 3.14159265358979323846;
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
  ll n, k, c = 0;
  cin >> n >> k;

  ld x, y;

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

    x = abs(x), y = abs(y);

    if (ceil(sqrt(x * x + y * y) ) <= k)
      c++;
  }
  cout << c;
  return 0;
}

Measured memory_bytes: 3844
# coding: utf-8
import time
import re
import math
import fractions

def main():
    A,B=map(int,input().split())
    index=B-A-1
    total=0
    for a in range(0,index+1):
        total+=a+1
    print(total-B)
start=time.time()
main()
#print("処理速度 {}sec".format(time.time()-start))
#"YNeos"[True::2]
#A=list(map(int,input().split()))
#A,B,C=map(int,input().split())
#n=int(input())
# global n,A,s,memo,mx,mn,L,B



Measured memory_bytes: 5044
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    
    rep(i, n - 1) {
        if ((a[i] + a[i + 1]) > x) {
            int s = a[i] + a[i + 1] - x;
            a[i + 1] = max(a[i + 1] - s, 0);
            ans += s;
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640