akhauriyash/Code-Regression huggingface dataset:
#おそらく上は偶数の処理がおかしい
k = int(input())        
#奇数の場合
if (k%2) == 1:
    o = (k-1) * (k+1) / 8
    #eはoと同じ数値
    print(int(2*o))
#偶数の場合 
else:
    o = k * (k+2) / 8
    e = k * (k-2) / 8
    print(int(o+e))

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
constexpr long long int Mod = 1000000007L;
int main() {
	int n, m, k; std::cin >> n >> m >> k;
	std::vector<long long int> factorial(n * m + 1, 1);
	std::vector<long long int> inverse(n * m + 1, 1);
	std::vector<long long int> inverse_factorial(n * m + 1, 1);
	for (auto i = 2; i <= n * m; ++i) {
		factorial[i] = (factorial[i - 1] * i) % Mod;
		inverse[i] = (Mod - (inverse[Mod % i] * (Mod / i) % Mod)) % Mod;
		inverse_factorial[i] = (inverse_factorial[i - 1] * inverse[i]) % Mod;
	}
	long long int result = 0;
	for (long long int h = 1; h < n; ++h) {
		auto score = ((n - h) * m) * h;
		result += score;
		result %= Mod;
	}
	for (long long int w = 1; w < m; ++w) {
		auto score = ((m - w) * n) * w;
		result += score;
		result %= Mod;
	}
	for (long long int h = 1; h < n; ++h) for (long long int w = 1; w < m; ++w) {
		auto score = ((n - h) * (m - w) * 2) * (h + w);
		result += score;
		result %= Mod;
	}
	auto others = ((factorial[n * m - 2] * inverse_factorial[n * m - k]) % Mod * inverse_factorial[k - 2]) % Mod;
	result = (result * others) % Mod;
	std::cout << result << std::endl;
}



Measured memory_bytes: 4992
N = int(input())
h = list(map(int, input().split()))

def cost(a, b):
    return abs(h[a] - h[b])

c = [0] * N
c[1] = cost(0, 1)

for i in range(2, N):
    c[i] = min(cost(i, i-1) + c[i-1], cost(i, i-2) + c[i-2])

print(c[-1])


Measured memory_bytes: 13980
import java.util.*;
public class Main {

	static int n, m;
	static int[] dx = {0,0,-1,1}, dy = {-1,1,0,0};
	static boolean[][] map, check;

	public static int dfs (int y, int x) {
		int ret = 0;
		for (int i = 0; i < 4; i++) {
			int nextX = x + dx[i];
			int nextY = y + dy[i];
			if (0 <= nextX && nextX < m &&
				0 <= nextY && nextY < n &&
				map[nextY][nextX] &&
				!check[nextY][nextX]) {

				check[nextY][nextX] = true;
				ret = Math.max(dfs(nextY,nextX) + 1,ret);
				check[nextY][nextX] = false;
			}
		}
		return ret;
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int ans = 0;
			m = sc.nextInt();
			n = sc.nextInt();
			sc.nextLine();
			if (m == 0 && n == 0) break;
			map = new boolean[n][m];
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++)
					map[i][j] = sc.nextInt() == 1;
			}
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (map[i][j]) {
						check = new boolean[n][m];
						ans = Math.max(dfs(i,j),ans);
					}
				}
			}
			System.out.println(ans);
		}
	}
}

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

#define faster      ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi          acos(-1.0)
#define nl          '\n'

///Library
#define mem(a,b)    memset(a,b,sizeof(a))
#define all(a)      a.begin(),a.end()
#define Sort(x)     sort(x.begin(),x.end())
#define Reverse(x)  reverse(x.begin(),x.end())
#define SortA(ar,s) sort(ar,ar+s)
#define SortD(ar,s) sort(ar,ar+s,greater<int>())
#define gcd(a,b)    __gcd(a,b)
#define lcm(a,b)    (a*(b/gcd(a,b)))
#define sq(x)       (x)*(x)

#define for0(a, n)      for(int i=a; i<n; i++)
#define for1(a, n)      for(int i=a; i<=n; i++)
#define rfor0(n, a)     for(int i=n-1; i>=a; i--)
#define rfor1(n, a)     for(int i=n; i>a; i--)

#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min(b,min(c,d)))
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max(b,max(c,d)))
#define ABS(x)             ((x)<0?-(x):(x))
#define pb                 push_back
#define mod                1000000007
#define end                printf("\n")
#define yes                printf("YES\n")
#define no                 printf("NO\n")

///data type
typedef long long int ll;
typedef unsigned long long int  llu;

int main()
{
    int n;
    cin>>n;
    int x,y,c=0,mx=0;
    while(n--)
    {
        cin>>x>>y;
        if(x==y)
            c++;
        else c=0;

        mx=max(c,mx);
        //cout<<mx<<nl;
    }
    if(mx>2)
        cout<<"Yes"<<nl;
    else cout<<"No"<<nl;
    return 0;
}


Measured memory_bytes: 3632
// ankit_singhal
#define boostit ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//using namespace __gnu_pbds;
using namespace std;

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define pii pair<ll,ll>
#define qi queue<ll>
#define mem(a,b) memset(a,b,sizeof(a))
#define print(a) cout<<a<<'\n'
#define sorted(arr) sort(arr.begin(),arr.end())
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define read(a) scanf("%d", &a)
#define f(a,n) for(ll i=a;i<n;i++)
#define in(a,n,arr) for(ll i=a;i<n;i++)cin>>arr[i];
#define in2(n,m,arr) for(ll i=0;i<n;i++){for(ll j=0;j<m;j++)cin>>arr[i][j];}
#define pown  1<<n
#define mod 1e9+7
#define mm 1e6
/*typedef tree<int, null_type, less<int>, rb_tree_tag,
 tree_order_statistics_node_update>
 ordered_set;
 typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
 tree_order_statistics_node_update>
 ordered_multiset;*/
//map<pii,ll> ma,visi;

/*vector<ll> v;
 void SieveOfEratosthenes(int n)
 {
 bool prime[n+1];
 memset(prime, true, sizeof(prime));
 
 for (int p=2; p*p<=n; p++)
 {
 if (prime[p] == true)
 {
 for (int i=p*p; i<=n; i += p)
 prime[i] = false;
 }
 }
 for (int p=2; p<=n; p++)
 if (prime[p])
 v.pb(p);
 }
*/
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
/*ll ans[(ll)mm];
ll get(ll x)
{
    //while(ans[x]!=x){x=ans[x];}
    if(ans[x]==x)return x;
    return ans[x]=get(ans[x]);
    
    //return;
}
void merge(ll a,ll b)
{
    ll temp=get(a);
    ll temp2=get(b);
    if(temp==temp2)return;
    //ans[temp]=temp2;
}*/
int main()
{
    boostit;
    ll t;
    t=1;
    //cin>>t;
    while(t--)
    {
        ll str1,str2;
        cin>>str1>>str2;
        ll ans=1,count=0;
        while(ans<str2)
        {
            ans--;
            ans+=str1;
            count++;
        }
        print(count);
    }
    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<stdio.h>
using namespace std;
 
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define INF 1<<25
 
int main()
{
	int n;
	cin >> n;
	if (n >= 1000) {
		cout << "ABD" << endl;
	} else {
		cout << "ABC" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 double A,B,H,M;
 double kakudo;
 double pi=M_PI;
 cin >> A >> B >> H >> M;
 kakudo=abs(M*6-(30*H+M*0.5));
 if(kakudo>=180){
   kakudo=360-kakudo;
 }
 kakudo=kakudo*pi/180.0;
 cout << fixed << setprecision(13);
 cout << sqrtl(A*A+B*B-2*A*B*cosl(kakudo)) <<endl;
}

Measured memory_bytes: 4120
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

class Program
{
    static void Main()
    {

        int[] nm = Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
        int N = nm[0];
        int M = nm[1];

        var requests =
            Enumerable.Range(0, M)
            .Select(n => Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray())
            .Select(arr => new { a = arr[0]-1, b = arr[1]-1 }) //1スタートは扱いにくいから0スタートに治す
            .ToArray();

        //まとめられる区間はまとめていく。
        //まとめるというのは、区間の重複領域を取ること。
        //既存の区間のいずれかと重複している→それらを重複領域に置き換える。
        //既存の区間のいずれとも重複していない→新規区間として登録。

        requests = requests.OrderBy(req => req.a).ToArray();

        int ans = 0;

        int currentSt = requests[0].a;
        int currentEd = requests[0].b - 1;

        foreach(var req in requests.Skip(1))
        {
            if (req.a <= currentEd)
            {
                currentSt = req.a;
                currentEd = Math.Min(currentEd, req.b - 1);
            }
            else
            {
                ans++;
                currentSt = req.a;
                currentEd = req.b - 1;
            }
        }

        ans++;

        Console.WriteLine(ans);
    }
    
}



static class MathUtil
{
    public static IEnumerable<IEnumerable<int>> GetPermutation(int n)
    {
        if (n == 0)
        {
            yield return Single(0);
            yield break;
        }

        for (int i = 0; i <= n; i++)
        {
            foreach (var x in GetPermutation(n - 1))
            {
                yield return Single(i).Concat(x.Select(itm => itm < i ? itm : itm + 1));
            }
        }
    }

    private static IEnumerable<int> Single(int x)
    {
        yield return x;
    }

    public static IEnumerable<int> EnumeratePrimeNumbers()
    {
        List<int> primes = new List<int>() { 2 };
        yield return 2;

        for (int i = 3; i < int.MaxValue; i++)
        {
            bool isPrime = true;
            int Sqrt = (int)Math.Sqrt(i) + 1;

            foreach (var prime in primes)
            {
                if (prime > Sqrt)
                {
                    break;
                }
                if (i % prime == 0)
                {
                    isPrime = false;
                    break;
                }
            }

            if (isPrime)
            {
                primes.Add(i);
                yield return i;
            }
        }
    }
}



Measured memory_bytes: 28724
import sys
input = sys.stdin.readline
from operator import itemgetter
sys.setrecursionlimit(10000000)
INF = 10**30
from math import factorial

# fac = [0] * (10**6+5)
# ifac = [0] * (10**6+5)
# d = 10**9 + 7

# def mpow(x, n):
#     ans = 1
#     while n != 0:
#         if n&1:
#             ans = ans * x % d
#         x = x*x % d
#         n = n >> 1
#     return ans

# def comb(a, b):
#     if a == 0 and b == 0:
#         return 1
#     if a < b or a < 0:
#         return 0
#     tmp = ifac[a-b] * ifac[b] % d
#     return tmp * fac[a] % d

def make_comb(m, d):
    def div(i, j):
        # 1/i mod(j)
        # calc i**(j-2) mod(j)
        p = j - 2
        ans = 1
        while p != 0:
            if p % 2 == 1:
                ans = (ans * i) % d
            i = i**2 % d
            p >>= 1
        return ans

    fac = [0] * (m+1)
    ifac = [0] * (m+1)
    # nCk
    fac[0] = 1
    ifac[0] = 1
    for i in range(m):
        fac[i+1] = (fac[i] * (i+1)) % d
        ifac[i+1] = (ifac[i] * div(i+1, d)) % d
    def comb(n, k):
        if n == 0 and k == 0:
            return 1
        if n < k or n < 0:
            return 0
        return (fac[n] * ifac[k] * ifac[n-k]) % d
    return comb

def main():
    x, y = map(int, input().strip().split())
    if (x + y) % 3 != 0:
        print(0)
        return
    k = (x+y) // 3
    q = x - k
    if x - 2 * q < 0 or q < 0:
        print(0)
        return
    comb = make_comb(10**6, 10**9+7)
    print(comb(k, q))

if __name__ == '__main__':
    main()


Measured memory_bytes: 58332
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<n; i++)
using namespace std;
typedef long long ll;
const ll INF =1e18L   +5;
int main()
{
    ll n,W;
    scanf("%lld%lld",&n,&W);
    vector<ll> w(n),v(n);
    REP(i,n) scanf("%lld%lld",&w[i],&v[i]);
    ll sum_v =0;
    REP(i,n) sum_v += v[i];
    vector<ll> dp(sum_v+1,INF);
    dp[0]=0;
    //dp[i] is the min weight with total value i
    REP(item,n){
        for(int j=sum_v - v[item];j>=0;j--){//it doesn't take same weights,> 0 will give wrong result 
            dp[j+v[item]]=min(dp[j+v[item]],dp[j]+w[item]);
        }
    }
    ll res=0;
    for(int i=0;i<=sum_v;i++){
        if(dp[i]<=W)
            res = max(res,(ll)i);
    }
    printf("%lld\n",res);       
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b){
		swap(a,b);
	}
	if(a>c){
		swap(a,c);
	}
	if(b>c){
		swap(b,c);
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
// typedef uint64_t ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();

int main() {
    int n;
    uint64_t mod = 1e9 + 7;
    cin >> n;
    vector<uint64_t> arr(n, 0);
    for(uint64_t& val: arr)
        cin >> val;
    vector<uint64_t> vec(60, 0);
    vector<uint64_t> fac(60, 0);
    uint64_t ans = 0;
    fac[0] = 1;
    for(int i = 1; i < 60; i++) {
        fac[i] = (fac[i-1] * 2) % mod;
    }
    uint64_t cnt = 0;
    for(int i = n-1; i >= 0; i--) {
        for(int d = 0; d < 60; d++) {
            if ((arr[i] & ((uint64_t)(1)<<d)) == 0) {
                ans += fac[d] * vec[d];
            } else {
                ans += fac[d] * (cnt-vec[d]);
                vec[d] += 1;
            }
            ans %= mod;
        }
        cnt += 1;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    string s,t; cin>>s>>t;
    if(s.size()>=t.size()) cout<<"No";
    else{
        if(s.size()+1==t.size()){int c=0;
            for(int i=0;i<s.size();i++) if(s[i]==t[i]) c++;
            if(c==s.size()) cout<<"Yes";
            else cout<<"No";
        }
        else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll n,m;
bool graph[55][55];
bool visited[55];
void dfs(int v){
  visited[v]=true;
  for(int v2=0;v2<n;v2++){
    if(graph[v][v2]==false)continue;
    if(visited[v2]==true)continue;
    dfs(v2);
  } 
}

int main(){
  cin>>n>>m;
  vector<ll> a(m),b(m);
  ll ans=0;
  fill(graph[0],graph[54],false);
  rep(i,m){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;
    graph[a[i]][b[i]]=true;
    graph[b[i]][a[i]]=true;
  }
  rep(i,m){
    fill_n(visited,55,false);
    graph[a[i]][b[i]]=false;
    graph[b[i]][a[i]]=false;
    dfs(0);
    rep(j,n){
      if(visited[j]==false){
        ans++;
        break;
      }
    }
    graph[a[i]][b[i]]=true;
    graph[b[i]][a[i]]=true;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
template<class T> using vt = vector<T>;
template<class T> using vvt = vector<vt<T>>;
template<class T> using ttt = tuple<T,T>;
using tii = tuple<int,int>;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define mt make_tuple
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define DIV int(1e9+7)
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-8;
//const double PI = M_PI;  
inline ll pow(ll x,ll n,ll m){ll r=1;while(n>0){if((n&1)==1)r=r*x%m;x=x*x%m;n>>=1;}return r%m;}
inline ll lcm(ll d1, ll d2){return d1 / __gcd(d1, d2) * d2;}

/*Coding Space*/
int main(){
  int n; cin >> n;
  vi a1(n);
  vi a2(n);
  rep(i,n)  cin >> a1[i];
  rep(i,n)  cin >> a2[i];
  
  int ans = 0;
  rep(i,n){
    int tans = 0;
    for(int index = 0; index <= i; ++index)
      tans += a1[index];
    for(int index = i; index < n; ++ index)
      tans += a2[index];
    ans = max(ans,tans);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
// -- Nitin
#include <bits/stdc++.h>
#define pb push_back
#define mkp make_pair
#define llu unsigned long long int
#define ll long long
#define ld long double
#define foi(a,n) for(int i = a; i < (int)n; i++)
#define foj(a,n) for(int j = a; j < (int)n; j++)
#define foin(a,n) for(int i = n; i >= a; i--)
#define fojn(a,n) for(int j = n; j >= a; j--)
#define bug(x) cerr << #x << " is " << x << endl;
#define isp2(x) x&&(!(x&(x-1)))
#define ln '\n'
#define ee 1000000007
#define eem 998244353
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define cases int tests; cin >> tests; while(tests--)

using namespace std;

ll fast(ll n,ll k){
    ll res = 1;
    n = n;
    while(k > 0){
        if ((k&1) == 1)
            res = (res * n);
        k = k>>1;
        n = (n * n);
    }
    return res;
}
 
//~ ll strsum(string s){
    //~ ll sm = 0, r = s.size();
    //~ foi(0,r)    sm += int(s[i]-'a');
    //~ return sm;
//~ }
 
//~ set <ll, greater <ll> > ss; //Prime Factors
//~ void pF(ll n)  {    
    //~ while (n % 2 == 0)  {  
        //~ ss.insert(2);  
        //~ n = n/2;  
    //~ }  
    //~ for (int i = 3; i <= sqrt(n); i = i + 2)  {   
        //~ while (n % i == 0)  {  
            //~ ss.insert(i); 
            //~ n = n/i;  
        //~ }  
    //~ }    
    //~ if (n > 2)  ss.insert(n);  
//~ }

//~ ll pre[1001][1001];

//~ ll go(ll n, ll k){
	//~ if(n==1) return 1;
	//~ else {
		//~ pre[n][k] = (go(n - 1, k) + k - 1) % n + 1;
		//~ return pre[n][k];
	//~ }
//~ }

//~ int dp[1002][1002];
//~ bool pal(string s){
	//~ for(int i = 0, j = s.size() - 1; i < s.size(); i++, j--){
		//~ if(s[i] != s[j]) return 0;
	//~ }
	//~ return 1;
//~ }

//~ void solve(){
	//~ int n;
	//~ cin >> n;		
//~ }


void go(){
	int n;
	cin >> n;
	ll a[n], sum = 0;
	foi(0, n) {
		cin >> a[i];
		sum = (sum%ee + a[i]%ee)%ee;
	}
	ll val = 0, ans = 0;
	for(int i = 0; i < n-1; i++){
		 val = (val%ee + a[i]%ee)%ee;
		 ll x = sum - val;
		 if(x < 0) x = (x+ee);
		 ans = (ans%ee + ((a[i]%ee)*x)%ee)%ee;
	}
	cout << ans % ee;
	
}

int main(){
    fio;
	//~ ll q, n, x, m , y;
	//~ string t;
	//~ for(int i = 1; i <= 1000; i++){
		//~ pre[1][i]=1;
		//~ go(1000,i);
	//~ }
	ll n, m, k;
    //~ cases
    {	
		go();
		cout << "\n";
	}
}
       
        


Measured memory_bytes: 5196
n = int(input())
a = list(map(int,input().split()))
a4 = []
a2 = []
odd = []
for i in range(n):
    if a[i] % 4 == 0:
        a4.append(a[i])
    elif a[i] % 2 == 0:
        a2.append(a[i])
    else:
        odd.append(a[i])
if len(a) > 3:
    if len(odd) <= len(a4):
        print('Yes')
    elif len(a2) == 0:
        if n %2 == 1 and len(odd) <= len(a4)+1:
            print('Yes')
        elif n%2 == 0 and len(odd) <= len(a4):
            print('Yes')
        else:
            print('No')
    else:
        print('No')
else:
    if a4 or len(a2) == n:
        print('Yes')
    else:
        print('No')
    


Measured memory_bytes: 63384
#include <stdio.h>

int main(void)
{
	int a,b;
	
	
	for(a=1;a<10;a++)
	{
		for(b=1;b<10;b++)
		{
			printf("%dx%d=%d\n",a,b,a*b);
		}
	}
	
	return 0;
}

Measured memory_bytes: 524
N, K = map(int, input().split())
A = list(map(int, input().split()))

zumi_hash = {}
zumi = [-1]*(2*(10**5))
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi_hash:
        zumi[i] = ima
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi_hash[ima] = True
    zumi[i] = ima
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_e = zumi.index(-1)
loop_s = zumi.index(zumi[loop_e-1])
zan_loop = K-loop_s
loop = zumi[loop_s:loop_e-1]
amari = zan_loop % (len(loop))
print(loop[amari])


Measured memory_bytes: 32384
#include <cstdio>

const int maxn=200000;

int read()
{
  int x=0,f=1;
  char ch=getchar();
  while((ch<'0')||(ch>'9'))
    {
      if(ch=='-')
        {
          f=-f;
        }
      ch=getchar();
    }
  while((ch>='0')&&(ch<='9'))
    {
      x=x*10+ch-'0';
      ch=getchar();
    }
  return x*f;
}

int n,a[maxn+10];
long long ans;

int main()
{
  n=read();
  for(int i=1; i<=n; ++i)
    {
      a[i]=read();
      if(a[i]>=i)
        {
          puts("-1");
          return 0;
        }
    }
  for(int i=2; i<=n; ++i)
    {
      if(a[i]>a[i-1]+1)
        {
          puts("-1");
          return 0;
        }
      if(a[i]==a[i-1]+1)
        {
          ++ans;
        }
      else
        {
          ans+=a[i];
        }
    }
  printf("%lld\n",ans);
  return 0;
}


Measured memory_bytes: 896
def abc148d_brick_break():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = 0
    val = 1
    for item in a:
        if item == val:
            val += 1
        else:
            cnt += 1
    if val == 1:
        print('-1')
    else:
        print(cnt)
abc148d_brick_break()

Measured memory_bytes: 100880
H,W=map(int,input().split())
S=['.'+input()+'.' for i in range(H)]
S.append('.'*(W+2))
S.insert(0,'.'*(W+2))
F=1

for i in range(H+2):
    for j in range(W+2):
        if S[i][j]=='#' and S[i+1][j]==S[i-1][j]==S[i][j+1]==S[i][j-1]=='.':
            F=0
            break

print(['No','Yes'][F])

Measured memory_bytes: 3064
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr int MOD = 1'000'000'007;

void solve() {
    LL n;
    cin >> n;
    LL ans = n;
    for (LL i = 1; i * i <= n; ++i) {
        if (n % i != 0) continue;
        LL a = i, b = n / i;
        ans = min(ans, a - 1 + b - 1);
    }
    cout << ans << endl;

}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 384
n = int(input())
a = input()
b = input()
c = input()

cnt = 0

for i in range(n):
	num_unique = len(list(set([a[i],b[i],c[i]])))

	if num_unique == 3:
		cnt += 2
	elif num_unique == 2:
		cnt += 1
	else:
		cnt += 0

print(cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h> 
#define Rg register 
#define IL inline  
#define Debug cout << " ----- " << endl ;  
using namespace std ; 
const int N = 3e4 + 5 ;  
int n , tot , sum , col[N] , dfn[N] , low[N] , top , sta[N] , pos[N] , block ; 
vector <int> v[N] ; bool In[N] ; 
struct node { int whe , id ; } a[N] ; 
bool cmp ( node A , node B ) { return A.whe < B.whe ; } 
IL void add( Rg int x , Rg int y ) { v[x].push_back(y) ; } 
IL int op ( Rg int x ) { return x % 2 == 0 ? x-1 : x+1 ; }   
IL int Sch ( Rg int Val ) { 
    Rg int l = 1 , r = (n<<1) , mid , Ans = 0 ; 
    if( Val <= a[l].whe ) return l ;  
    if( Val >= a[r].whe ) return r ; 
    while( l <= r ) { 
    	mid = l+r >> 1 ; 
    	if( Val <= a[mid].whe ) Ans = mid , r = mid - 1 ; 
		  else l = mid+1 ;  
	} 
	return Ans ; 
} 
void tarjan( Rg int x ) { 
	In[x] = 1 ; dfn[x] = low[x] = ++ tot ; sta[++top] = x ;  
	for(Rg int i=0 ; i<v[x].size(); i++) { 
		int u = v[x][i] ; 
		if( !dfn[u] ) tarjan( u ) , low[x] = min( low[x] , low[u] ) ; 
		  else if( In[u] ) low[x] = min( low[x] , dfn[u] ) ;  
	} 
	if( dfn[x] == low[x] ) { 
	     sum ++ ; int per = sta[top] ;  
	     while( per != x ) 
	         col[per] = sum , In[per] = 0 , per = sta[--top] ; 
		 col[x] = sum , In[x] = 0 , top -- ;  
	} 
} 
void Build( int fro , int x , int y ) { 
    if( x > y ) return ; int l = pos[x] , r = pos[y] ; 
	if( l == r ) { for(Rg int i=x; i<=y; i++) add( fro , op(a[i].id) ) ; return ; } 
	for(Rg int i=x; i<=l*block; i++) add( fro , op(a[i].id) ) ; 
	for(Rg int i=l+1; i<r; i++) add( fro , i+(n<<1) ) ;  
	for(Rg int i=(r-1)*block+1 ; i<=y; i++) add( fro , op(a[i].id) )  ; 
} 
bool check( int H ) { 
    for(Rg int i=1; i<=(n<<1)+pos[n] ; i++) col[i] = dfn[i] = low[i] = 0 ; 
    for(Rg int i=1; i<=(n<<1)+pos[n] ; i++) v[i].clear( ) ; 
    for(Rg int i=1; i<=(n<<1) ; i++) v[(n<<1)+pos[i]].push_back(op(a[i].id)) ; 
    tot = sum = top = 0 ; int l , r ; 
    for(Rg int i=1; i<=(n<<1) ; i++) {  
        l = Sch( a[i].whe-H+1 ) ; r = Sch( a[i].whe+H ) ; 
        Build( a[i].id , l , i-1 ) ; Build( a[i].id , i+1 , r-1 ) ; 
	} 
	for(Rg int i=1; i<=(n<<1); i++) if( !dfn[i] ) tarjan(i) ; 
	for(Rg int i=1; i<=n; i++) if( col[a[i].id] == col[op(a[i].id)] ) return 0 ; 
	return 1 ; 
} 
signed main() { 
    ios::sync_with_stdio(false) ; 
    cin.tie(0) ; cout.tie(0) ; 
    cin >> n ; 
    for(Rg int i=1; i<=n; i++) 
      cin >> a[(i<<1)-1].whe >> a[i<<1].whe , 
       a[(i<<1)-1].id = (i<<1) - 1 , a[i<<1].id = ( i<<1 ) ; 
    sort( a+1 , a+(n<<1)+1 , cmp ) ; 
    block = sqrt( n << 1 ) ; 
    for(Rg int i=1; i<=(n<<1); i++) pos[i] = (i-1)/block+1 ; 
    int l = 1 , r = a[n<<1].whe - a[1].whe , mid , Ans = 0  ;  
    while( l <= r ) { 
    	mid = l+r >> 1 ; 
    	if( check(mid) ) Ans = mid , l = mid+1 ; 
    	  else r = mid-1 ; 
	}  
	cout << Ans << '\n' ;
	return 0 ; 
} 

Measured memory_bytes: 84224
#include <cstdio>

int main(){
    char s[1201];
    scanf("%[^\n]", s);

    for(int i = 0; s[i] != '\0'; i++){
        char c = s[i];
        if(c >= 65 && c <= 90){
            s[i] = c + 32;
        }
        else if(c >= 97 && c <= 122){
            s[i] = c - 32;
        }
    }

    printf("%s\n", s);

    return 0;

}


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

int main() {
  
  string S,T;
  cin >> S >> T;
   
  int ans = 0;
  if(S.at(0) == T.at(0)){
  	ans++;
  }
  if(S.at(1) == T.at(1)){
  	ans++;
  }
  if(S.at(2) == T.at(2)){
  	ans++;
  }
  
  cout << ans << endl;
 
}

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

const int MAX_N = 1006;
int N, M, A, B;
int g[MAX_N][MAX_N];

void solve()
{
	for(int i=0;i<N;++i){
		for(int j=0;j<M;++j){
			if(i<B && j<A) cout << 0;
			else if(i>=B && j<A) cout << 1;
			else if(i<B && j>=A) cout << 1;
			else cout << 0;
		}
		cout << "\n";
	}
}

int main()
{
	cin >> N >> M >> A >> B;
	solve();
	return 0;
}

Measured memory_bytes: 1280
use std;
use std::collections::VecDeque;
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}

/*
ここまでテンプレ
*/
fn ord(a: (i32, i32), b: (i32, i32)) -> bool {
    if (a.0 < b.0) {
        true
    } else {
        false
    }
}
const INF: i32 = 1 << 13;
fn main() {
    let N = read::<i32>();
    let mut Red: Vec<(i32, i32)> = vec![(0, 0); N as usize];
    let mut Blue: Vec<(i32, i32)> = vec![(0, 0); N as usize];
    for i in 0..N as usize {
        let tmp = read_vec::<i32>();
        Red[i] = (tmp[0], tmp[1]);
    }
    for i in 0..N as usize {
        let tmp = read_vec::<i32>();
        Blue[i] = (tmp[0], tmp[1]);
    }
    Blue.sort_unstable();
    //println!("{:?}", Blue);
    let mut ans: u32 = 0;
    for i in 0..N as usize {
        let mut id = -1;
        let mut num = -1;
        for j in 0..N as usize {
            if Red[j].1 < Blue[i].1 && Red[j].0 < Blue[i].0 {
                if num < Red[j].1 {
                    num = Red[j].1;
                    id = j as i32;
                }
            }
        }
        if id == -1 {
            continue;
        }
        ans += 1;
        Red[id as usize].0 = INF;
        Red[id as usize].1 = INF;
    }
    println!("{}", ans);
}


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

int main(){

  string S;
  string N = "keyence";
  int count=0;

  getline(cin, S);
  int h = S.size();

  if(S[0]=='k'&&S[1]=='e'&&S[2]=='y'&&S[3]=='e'&&S[4]=='n'&&S[5]=='c'&&S[6]=='e') count++;
  if(S[0]=='k'&&S[1]=='e'&&S[2]=='y'&&S[3]=='e'&&S[4]=='n'&&S[5]=='c'&&S[h-1]=='e') count++;
  if(S[0]=='k'&&S[1]=='e'&&S[2]=='y'&&S[3]=='e'&&S[4]=='n'&&S[h-2]=='c'&&S[h-1]=='e') count++;
  if(S[0]=='k'&&S[1]=='e'&&S[2]=='y'&&S[3]=='e'&&S[h-3]=='n'&&S[h-2]=='c'&&S[h-1]=='e') count++;
  if(S[0]=='k'&&S[1]=='e'&&S[2]=='y'&&S[h-4]=='e'&&S[h-3]=='n'&&S[h-2]=='c'&&S[h-1]=='e') count++;
  if(S[0]=='k'&&S[1]=='e'&&S[h-5]=='y'&&S[h-4]=='e'&&S[h-3]=='n'&&S[h-2]=='c'&&S[h-1]=='e') count++;
  if(S[0]=='k'&&S[h-6]=='e'&&S[h-5]=='y'&&S[h-4]=='e'&&S[h-3]=='n'&&S[h-2]=='c'&&S[h-1]=='e') count++;
  if(S[h-7]=='k'&&S[h-6]=='e'&&S[h-5]=='y'&&S[h-4]=='e'&&S[h-3]=='n'&&S[h-2]=='c'&&S[h-1]=='e') count++;

  if(count){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 111
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;

ll gcd(ll n1,ll n2){
	if(!n1)return n2;
	if(!n2)return n1;
	if(n1%n2==0)return n2;
	return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
	base%=mod;
	ll ans=1;
	while(exponent){
		if(exponent&1)ans=(ans*base)%mod;
		base=(base*base)%mod;
		exponent/=2;
	}
	ans%=mod;
	return ans;
}
int parent[upperlimit+1];
int size[upperlimit+1];
void init(){
	for(int i=0;i<=upperlimit;i++){
		parent[i]=i;
		size[i]=1;
	}
}
int find(int node){
	while(node!=parent[node]){
		parent[node]=parent[parent[node]];
		node=parent[node];
	}
	return node;
}
void merge(int a,int b){
	a=find(a);
	b=find(b);
	if(a!=b){
		if(size[a]<size[b])swap(a,b);
		parent[b]=a;
		size[a]+=size[b];
	}
}
int a[upperlimit+1];
int b[upperlimit+1];
int main()
{
	int i,j,k,n,m;
	sd(n);sd(m);
	for(i=1;i<=m;i++){
		sd(a[i]);sd(b[i]);
	}
	int answer=0;
	for(i=1;i<=m;i++){
		init();
		for(j=1;j<=m;j++)if(j!=i)merge(a[j],b[j]);
		if(find(a[i])!=find(b[i]))answer++;
	}
	pdn(answer);
	return 0;
}

Measured memory_bytes: 256
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def inc(n):
  ans = 0
  i = 1
  while True:
    if n - i >= 0:
      n -= i
      i += 1
      ans += 1
    else:
      break
  return ans

import collections

n = int(input())

c = collections.Counter(prime_factorize(n))

num = c.values()

ans = 0

for i in num:
  ans += inc(i)

print(ans)

Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<ll, ll> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
double PI = acos(-1);

void solve()
{	
	int n; cin >> n;
	vector<double> a(n),b(n);
	rep(i, n)cin >> a[i];
	rep(i, n)cin >> b[i];
	double ans_1 = 0, ans_2 = 0,ans_3 = 0,ans_inf = 0;
	rep(i, n){ans_1 += abs(a[i]-b[i]);chmax(ans_inf,abs(a[i]-b[i]));}
	rep(i ,n)ans_2 += pow(a[i]-b[i],2);
	ans_2 = pow(ans_2,0.5);
	rep(i ,n)ans_3 += pow(abs(a[i]-b[i]),3);
	ans_3 = pow(ans_3,1./3.);
	cout << ans_1 << endl;
	cout << ans_2 << endl;
	cout << ans_3 << endl;
	cout << ans_inf << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}



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


int main() {
    
    int X,ans;
    string s [7] = {"thu","fri","sat","sun","mon","tue","wed"};
    cin >> X;
    
    ans = X % 7;
    
    std::cout << s[ans] << std::endl;

}


Measured memory_bytes: 3196
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <deque>
#include <functional>
#include <initializer_list>
#include <math.h>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <queue>
#include <vector>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); --(i))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define SORT(A) std::sort((A).begin(), (A).end())
#define ALL(A) (A).begin(), (A).end()
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())

using lli = long long int;
using pii = std::pair<int, int>;

void VintOut(std::vector<int>& A){
    const int n = A.size();
    if(n == 0){putchar('\n'); return;}
    printf("%d", A[0]);
    for(int i = 1; i < n; ++i) printf(" %d", A[i]);
    putchar('\n');
}
void VintOut(std::vector<long long int>& A){
    const int n = A.size();
    if(n == 0){ putchar('\n'); return;}
    printf("%lld", A[0]);
    for(int i = 1; i < n; ++i) printf(" %lld", A[i]);
    putchar('\n');
}

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

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

inline bool bitUP(int state, int k){ return (state >> k) & 1; }
inline bool bitUP(long long int state, int k){ return (state >> k) & 1;}


// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
    int k, X; scanf("%d%d", &k, &X);
    if(500 * k >= X) puts("Yes");
    else puts("No");


    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

int n, ans;

int f(int x) {
	int ret = 0;
	while (x) {
		ret += x % 10;
		x /= 10;
	}
	return ret;
}

int main() {
	
	scanf("%d", &n);
	
	ans = f(1) + f(n - 1);
	
	for (int i = 2; i < n; i++)
		ans = min(ans, f(i) + f(n - i));
	
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 256
L= [list(map(int, input().split())) for i in range(3)]
s=True

if L[1][1]!=L[1][0]-L[0][0]+L[0][1]:
    s=False
if L[1][2]!=L[1][0]-L[0][0]+L[0][2]:
    s=False
if L[2][1]!=L[2][0]-L[0][0]+L[0][1]:
    s=False
if L[2][2]!=L[2][0]-L[0][0]+L[0][2]:
    s=False
if s:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 8992
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int one = sc.nextInt();
		int two = sc.nextInt();
		
		if(one>9||two>9) {
			System.out.println(-1);
		}
		else
			System.out.println(one*two);
	
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define sz() size()
#define fr first
#define sc second
#define pb push_back
#define er erase
#define in insert
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define mp make_pair
#define int long long
#define rc(s) return cout<<s,0
//#define cin fin
//#define cout fout
using namespace std;


const int nmax=1e3+5;
const int mod=1e9+7;
const int mod1=998244353;

int n,ans[100005],x,y,z;
vector<pi>nod[100005];

void dfs(int s,int par){
    for(int i=0;i<nod[s].size();i++){
        if(nod[s][i].fr!=par){
            if(nod[s][i].sc%2==1){if(ans[s]==1) ans[nod[s][i].fr]=0;
            else ans[nod[s][i].fr]=1;}
            else ans[nod[s][i].fr]=ans[s];
            dfs(nod[s][i].fr,s);
        }
    }
}

int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie();cout.tie();
    cin >> n;
    for(int i=1;i<n;i++){
        cin >> x >> y >> z;
        nod[x].pb({y,z});
        nod[y].pb({x,z});
    }
    dfs(1,-1);
    for(int i=1;i<=n;i++) cout<<ans[i]<<'\n';
}


Measured memory_bytes: 9216
#include "iostream"
#include "vector"
#include "array"
#include "string"
#include "algorithm"
#include "functional"
#include <math.h>


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



//B
int main(void) {
	int n;
	cin >> n;
	int max = 0, sum = 0;
	rep(0, n) {
		int x;
		cin >> x;
		if (x > max) max = x;
		sum += x;
	}
	if (sum - max > max) cout << "Yes" << endl;
	else cout << "No" << endl;

}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100

int main(void){
	
	int A[MAX][MAX], b[MAX], c[MAX], i, j, m, n;
	scanf("%d %d", &n, &m);
	
	for(i = 0; i < n; i++){
		for(j = 0; j < m; j++){
			scanf("%d", &A[i][j]);
		}
	}

	for(i = 0; i < m; i++){
		scanf("%d", &b[i]);
	}
	
	for(i = 0; i < n; i++){
		c[i] = 0;
		for(j = 0; j < m; j++){
			c[i] += A[i][j] * b[j];			
		}
	}

	for(i = 0; i < n; i++){
		printf("%d\n", c[i]);
	}

	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
  long long N;
  cin>>N;
  long long ans=0;
  //約数のペアを求める
  long long count=1;
  while(count*count<=N){
    if(N%count==0 && N/count>count+1){
      ans+=((N/count)-1);
    }
    count+=1;
  }
  cout<<ans<<"\n";
return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }



int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r;
    cin >> r;
    cout << r * r << endl;
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <memory>
#include <memory.h>
#include <fstream>
#include <cmath>
#include <math.h>
#include <numeric>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <sstream>
#include <cstdlib>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <map>
#include <iomanip>
#include <list>
#include <cctype>
#include <algorithm>
#include <complex>

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

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<double, double> Pd;
typedef pair<int, P> PP;
typedef pair<int, PP> PPP;
const int INF = 1 << 29;
const double EPS = 1E-10;

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

int main(){
	map<string, int> mp;
	char str[20];
	printf("?aa\n");
	mp[string("aa")]++;
	fflush(stdout);
	while(true){
		scanf("%s", &str);

		if(str[0] != 'a' || mp[string(str)] || strlen(str) > 2) {
			printf("!OUT\n");
			break;
		}else{
			mp[string(str)]++;
			if(strlen(str) == 1){
				printf("?aaa\n");
				fflush(stdout);
			}else{
				printf("?%ca\n", str[1]);
				string a;
				a.push_back(str[1]);
				a.push_back('a');
				mp[a]++;
				fflush(stdout);
			}
		}
	}
	return 0;
}

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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> s(n);
    {
        string buf;
        cin>>buf;
        for(int i=0;i<n;i++) s[i]=buf[i]-'0';
    }
    int head=0,tail=0;
    int cnt=0;
    int res=0;
    while(head<n){
        if((tail+1<n && s[tail+1]==1) || cnt<k){
            if(tail+1<n){
                tail++;
            }
            else{
                tail=n-1;
                res=max(res,tail-head);
                break;
            }
            if(s[tail]==1 && s[tail-1]==0) cnt++;
        }
        else{
            res=max(res,tail-head);
            head++;
            if(head==n) break;
            if(s[head]==1 && s[head-1]==0) cnt--;
        }
    }
    cout<<res+1<<endl;
    

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define mp make_pair
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline int read(){
	int x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(int a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(int a){
	write(a); puts("");
}
const int mod=1000000007,N=2;
struct matrix{
	int a[N][N];
	inline int* operator [] (int x){
		return a[x];
	}
	void clear(){
    	memset(a,0,sizeof(a));
	}
}zs;
int n,m,heng,zong,lr,ud,sum;
ll k;
char ch[1005][1005];
matrix operator *(matrix a,matrix b){
	matrix tmp; tmp.clear(); 
	for(int i=0;i<2;i++){
		for(int j=0;j<2;j++){
			for(int k=0;k<2;k++){
				tmp[i][j]=(tmp[i][j]+(ll)a[i][k]*b[k][j])%mod;
			}
		}
	}
	return tmp;
}
matrix ksm(matrix zs,ll k){
	matrix ans; ans.clear(); ans[0][0]=1;
	for(;k;k>>=1){
		if(k&1)ans=ans*zs;
		zs=zs*zs;
	}
	return ans;
}
inline int po(ll a,ll b){
	b%=mod-1; int ans=1;
	for(;b;b>>=1){
		if(b&1)ans=ans*a%mod;
		a=a*a%mod;
	}
	return ans;
}
int main(){
	n=read(); m=read(); cin>>k;
	for(int i=1;i<=n;i++)scanf("%s",ch[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++)if(ch[i][j]=='#'){
			if(ch[i][j+1]=='#')heng++;
			if(ch[i+1][j]=='#')zong++;
			sum++;
		}
	}
	for(int i=1;i<=n;i++)if(ch[i][1]=='#'&&ch[i][m]=='#')lr++;
	for(int i=1;i<=m;i++)if(ch[1][i]=='#'&&ch[n][i]=='#')ud++;
	if(lr&&ud)puts("1");
	else if(!lr&&!ud)cout<<po(sum,k-1)<<endl;
	else{
		if(ud)swap(lr,ud),swap(heng,zong);
		zs[0][0]=sum; zs[0][1]=heng; zs[1][1]=lr;
		matrix p=ksm(zs,k-1);
		cout<<(p[0][0]-p[0][1]+mod)%mod<<endl;
	}
}


Measured memory_bytes: 1280
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
const ll INF = 10000000000;
int main() {
    int n;
    cin >> n;
    bool check = false;
    for (int i = 0; i < n; i++) {
        ll x; 
        cin >> x;
        if (x % 2 == 1) {
            check = true;
        }
    }
    if(check) {
        cout << "first";
    }
    else {
        cout << "second";
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<math.h>
#include<vector>
#define pp pair<int, int>
using namespace std;


int main() {
    int n;
    cin >> n;
    vector<pp> v;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v.push_back(make_pair(a, b));
    }
    bool flag = false;
    for(int i = 0; i < n-2; i++){
        if(v[i].first == v[i].second && v[i+1].first == v[i+1].second && v[i+2].first == v[i+2].second){
            flag = true;
            break;
        }
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}

Measured memory_bytes: 3628
#define DBG 0 //submit 0
#define ll long long
#if DBG
    #include <algorithm>
    #include <array>
    #include <ctime>
    #include <cstdlib>
    #include <string>
    #include <vector>
    #include <unordered_map>
    #include <iostream>
    #include <cmath>
    #include <numeric>
#else
    #include <bits/stdc++.h>
#endif

using namespace std;


int main(){
    int i,N;
    ll ans=0;

    unordered_map<string, ll> mp;
    string s;

    cin >> N;
    for(i=0;i<N;i++){
        cin >> s;
        sort(s.begin(),s.end());
        auto itr = mp.find(s);
        if( itr != mp.end() ) {
            mp[s]++;
        } else {
            mp[s] = 0;
        }
    }
    
    for(auto itr = mp.begin();itr != mp.end();itr++){
        ans += itr->second * (itr->second+1) / 2;
    }

    cout << ans << endl;
}


Measured memory_bytes: 10660
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int64_t, int64_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int64_t N, X, Y;
  cin >> N >> X >> Y;
  vector<int64_t> counts(N, 0);
  for (int64_t i = 1; i <= N; ++i) {
    for (int64_t j = i + 1; j <= N; ++j) {
      int64_t distance;
      if (i <= X && j >= Y) {
        distance = (X - i) + 1 + (j - Y);
      } else if (i <= X) {
        distance = (X - i) + min(j - X, Y - j + 1);
      } else if (j >= Y) {
        distance = min(Y - i, i - X + 1) + (j - Y);
      } else {
        distance = min(j - i, (i - X) + 1 + (Y - j));
      }
      ++counts[distance];
    }
  }
  for (int64_t distance = 1; distance < N; ++distance) {
    cout << counts[distance] << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    int l[n];
    int max = -1;
    int sum = 0;
    for(int i = 0;i < n;i++) {
        cin >> l[i];
        sum+=l[i];
        if(l[i]>max) {
            max = l[i];
        }
    }
    if(max<sum-max) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256