akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define FORR(i, a, b) for(int i = b-1; i >= a; i--)
typedef long long ll;
const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

const int MAX_N = 3010;
int N;
string S;
mint dp[MAX_N][MAX_N] = {0}; // dp[i][j] := (1-indexed)i文字目まででjで終わる順列の数

int main(){
    cin >> N >> S;

    dp[1][1] = 1;

    FOR(i, 2, N+1){
        if(S[i-2] == '<'){
            FOR(j, 1 , i+1){
                //FOR(k, 1, j){
                dp[i][j] += dp[i][j-1] + dp[i-1][j-1];
                //}
            }
        }else{
            FORR(j, 1, i+1){
                //FOR(k, j, i){
                    dp[i][j] += dp[i-1][j] + dp[i][j+1];
                //}
            }
        }
    }
    /* FOR(i,1,N+1){
        FOR(j,1,N+1) cout << dp[i][j] << " ";
        cout << endl;
    } */

    mint ans = 0;
    for(int i = 1; i <= N; i++) ans += dp[N][i];
    cout << ans << endl;
}

Measured memory_bytes: 35584
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int N = 2000 + 10 ;
int n , l[N] , r[N] , res[N] ;
string a , b ;

inline int sum (int a , int b) {
	int res = a + b ;
	if (res >= n) res -= n ;
	return res ;
}

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

	cin >> a >> b ;
	n = _sz(a) ;

	for (int i = 0 ; i < n ; i ++) l[i] = r[i] = n + 1 ;

	for (int i = 0 ; i < n ; i ++) {
		if (b[i] == '0') continue ;

		for (int j = 0 ; j < n ; j ++) {
			l[j] = min(l[j] , sum(j , n - i)) ;
			r[j] = min(r[j] , sum(i , n - j)) ;
		}
	}	

	for (int i = 0 ; i < n ; i ++)
		if (a[i] == '1' && l[i] > n) return cout << "-1\n" , 0 ;

	int ans = 10 * n ;

	for (int i = 0 ; i <= n ; i ++) {
		// move right
		memset(res , 0 , sizeof res) ;
	
		int mx = 0 , su = i ;
		for (int j = 0 ; j < n ; j ++) {
			int k = sum(j , i) ;

			if (a[j] != b[k]) {
				if (r[j] > i) res[r[j] - 1] = max(res[r[j] - 1] , l[j]) ;
				su ++ ;
			}
		}

		for (int j = n ; j >= 0 ; j --) {
			ans = min(ans , su + 2 * max(j - i , 0) + 2 * res[j]) ;	
			if (j) res[j - 1] = max(res[j - 1] , res[j]) ;
		}

		// move left
		memset(res , 0 , sizeof res) ;

		mx = 0 , su = i ;
		for (int j = 0 ; j < n ; j ++) {
			int k = sum(j , n - i) ;

			if (a[j] != b[k]) {
				if (l[j] > i) res[l[j] - 1] = max(res[l[j] - 1] , r[j]) ;
				su ++ ;
			}
		}

		for (int j = n ; j >= 0 ; j --) {
			ans = min(ans , su + 2 * max(j - i , 0) + 2 * res[j]) ;
			if (j) res[j - 1] = max(res[j - 1] , res[j]) ;
		}
	}

	cout << ans << '\n' ;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<=b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

string s;

int main(){
    INIT;
    cin >> s;
    char c = s[0];
    FOR(i,1,s.size()) {
        if(s[i] == c) {
            cout << "Bad";
            return 0;
        }
        c = s[i];
    }
    cout << "Good";
}

Measured memory_bytes: 256
from itertools import permutations

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

field = [["."] * 8 for _ in range(8)]

# 列
column = [i for i in range(8)]
# 行
row = [i for i in range(8)]

for r, perm_column in rc:
    column.remove(perm_column)
    row.remove(r)

    field[r][perm_column] = "Q"

dir_r = [1, 1, -1, -1]
dir_c = [1, -1, -1, 1]


def queen_check(field, perm_column):
    for i, j in zip(row, perm_column):
        for dr, dc in zip(dir_r, dir_c):
            r, c = i, j
            while True:
                r += dr
                c += dc

                if r < 0 or r >= 8 or c < 0 or c >= 8:
                    break

                if field[r][c] == "Q":
                    return False

    return True


for perm_column in permutations(column):
    for i, j in zip(row, perm_column):
        field[i][j] = "Q"

    if queen_check(field, perm_column):
        for f in field:
            print("".join(f))
    for i, j in zip(row, perm_column):
        field[i][j] = "."



Measured memory_bytes: 5656
N = int(input())
S = list(input())

black_sum = [0]*(N+1)
white_sum = [0]*(N+1)
ans = S.count('.')
for i in range(N):
    key_black = 0
    key_white = 0
    if S[i]=='#':
        key_black = 1
    else:
        key_white = 1

    black_sum[i+1]=black_sum[i]+key_black
    white_sum[i+1]=white_sum[i]+key_white
tmp = 0
for i in range(1,len(black_sum)):
    
        left = black_sum[i]  #境界左の黒石の数
        right = white_sum[-1]-white_sum[i]  #境界右の白石の数
        tmp = left + right
        ans = min(tmp,ans)

print(ans)

Measured memory_bytes: 20448
#include <iostream>
#define int long long
using namespace std;

signed main(){
	int n,a[2000];
	static int dp[2000][2000] = {};
	cin >> n;
	for(int i = 0;i < n;i++) {
		cin >> a[i];
		if(n % 2) dp[i][i] = a[i];
	}
	for(int i = 1;i < n;i++){
		for(int j = 0;j < n;j++){
			if((n - i) % 2) dp[j][(j + i) % n] = max(dp[j][(j + i - 1) % n] + a[(j + i) % n],dp[(j + n + 1) % n][(j + i) % n] + a[j]);
			else if(a[j] > a[(j + i) % n]) {
				dp[j][(j + i) % n] = dp[(j + n + 1) % n][(j + i) % n];
			}else{
				dp[j][(j + i) % n] = dp[j][(j + i - 1) % n];
			}
		}
	}
	int ma = 0;
	for(int i = 0;i < n;i++) ma = max(dp[i][(i + n - 1) % n],ma);
	cout << ma << endl;
	return 0;
}

Measured memory_bytes: 34352
def main():
    s = input()
    len_s = len(s)

    for i in range(1, len_s - 1):
        if (len_s - i) % 2 != 0:
            continue
        if s[:(len_s - i) // 2] == s[(len_s - i) // 2: len_s - i]:
            print(len_s - i)
            exit()


if __name__ == "__main__":
    main()


Measured memory_bytes: 80284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<algorithm>
#include<vector>
using namespace std;

int main()
{
    int n;
     while(cin>>n)
     { 
         if(n<1200)
            cout<<"ABC"<<endl;
         else if( n<2800)
            cout<<"ARC"<<endl;
         else
             cout<<"AGC"<<endl;

     }
     return 0;
}



Measured memory_bytes: 256
import java.util.*;

class Main {
    static int a,b,c;
    static int count = 0;
  
    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      a = sc.nextInt();
      b = sc.nextInt();
      c = sc.nextInt();
      for (int i=a; i<=b; i++) {
        if (c % i == 0){
          count++;
      }
      }
       System.out.println(count);
    }
}


Measured memory_bytes: 26412
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/trie_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef trie<string, null_type, trie_string_access_traits<>, pat_trie_tag, trie_prefix_search_node_update> pref_trie;
typedef unsigned long long BITMASK; typedef long long ll; typedef long double ld;
#define has_bit(bit_mask, x) ((bit_mask) & (1ULL << (x)))
#define turn_on_bit(bit_mask, x) (bit_mask |= (1ULL << (x)))
#define turn_off_bit(bit_mask, x) (bit_mask &= (~(1ULL << (x))))
#define smallest_on_bit(bit_mask) (__builtin_ctzint((bit_mask) & (-(bit_mask))))
#define CLOCK_START clock_t chrono_clk_beg = clock()
#define CLOCK_END clock_t chrono_clk_end = clock(); cerr << (double(chrono_clk_end - chrono_clk_beg) / CLOCKS_PER_SEC) << " sec"
#define bug(args ...) cerr << __LINE__ << ">> ", err(new istringstream(string(#args)), args), cerr << '\n'
#define decToBin(name, num) string name = bitset<8>(num).to_string();
#define binToDec(name, binary) unsigned long name = bitset<8>(binary).to_ulong();
#define radToDeg(name, radians) double name = radians * 180 / M_PI;
#define all(x) x.begin(), x.end()
#define mapfind(mp, x) (mp.find(x) != mp.end())
#define arrfind(arr, x) (find(all(arr), x) != arr.end())
#define removeDuplicates(vec) sort(vec.begin(), vec.end()); vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define printMat(mat) for (auto &x : mat) { for (auto &y : x) cout << y << " "; cout << '\n'; }
#define printArr(arr) for (auto &x : arr) cout << x << " "; cout << '\n';
#define ceil(a, b) ((a+b-1)/b)
#define int ll
#define double ld
#define INF (1LL<<62)
#define M_PI 3.14159265358979323846
void err(istringstream *iss) {} template<typename T, typename ... Args> void err(istringstream *iss, const T &_val, const Args & ... args) { string _name; *iss >> _name; if (_name.back()==',') _name.pop_back(); cerr << _name << " = " << _val << "; ", err(iss, args ...); }
void str_replaceAll(string& str, const string& from, const string& to) { if(from.empty()) return; size_t start_pos = 0; while((start_pos = str.find(from, start_pos)) != std::string::npos) { str.replace(start_pos, from.length(), to); start_pos += to.length(); } }
#define MOD 1000000007

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    string s, t;
    cin >> s >> t;
    int dp[s.size()+1][t.size()+1] {};
    for (int i = 1; i <= s.size(); ++i)
        for (int j = 1; j <= t.size(); ++j)
            dp[i][j] = (s[i-1] == t[j-1]) ? dp[i-1][j-1]+1 : max(dp[i-1][j], dp[i][j-1]);
    
    stringstream ss;
    int _i = s.size(), _j = t.size();
    while (_i > 0 && _j > 0)
    {
        if (dp[_i][_j] == dp[_i-1][_j]) _i--;
        else if (dp[_i][_j] == dp[_i][_j-1]) _j--;
        else { ss << s[_i-1]; _i--, _j--; }
    }
    string res = ss.str();
    reverse(all(res));
    cout << res << '\n';
    return 0;
}

Measured memory_bytes: 70656
#include<bits/stdc++.h>
using  namespace std;
#define ll long long
#define pb push_back
#define sc second
#define fr first
#define mp make_pair
const int N = 2e5 + 10 , OO = 1e9 + 2, Max = 50 + 10;
const ll  MOD = 998244353 ;
ll dp[N];
ll w[N] , v[N];
 int n , weight ;
int solve(int i,int we) {
    if(we < 0)
        return -OO;
    if(i == n + 1)
        return 0;
    int c1 = solve(i + 1,we - w[i]) + v[i];
    int c2 = solve(i + 1,we);
    return max(c1,c2);
}
int main() {

    cin >> n  >> weight;
    for(int i = 1;i<=n;++i) {
        cin >> w[i] >> v[i];
    }
   // cout << solve(1,weight) << endl;
    ll ans =0 ;

    for(int i = 1;i<=n;++i) {
        for(int j = weight - w[i];j>=0;--j) {
            dp[j + w[i]] = max(dp[j + w[i]] , dp[j] + v[i]);
        }
    }
    for(int i = 0;i<=weight;++i) {
        ans = max(ans,dp[i]);
    }
    cout << ans << endl;
}


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

using namespace std;

enum Diceface {
	DICETOP,
	DICEFRONT,
	DICERIGHT,
	DICELEFT,
	DICEBACK,
	DICEBOTTOM,
	DICENUM
};

class Dice {
private:
	int *face;
public:
	Dice( int top, int front, int right, int left, int back, int bottom ) {
		face = new int[6];
		face[DICETOP] = top;
		face[DICEFRONT] = front;
		face[DICERIGHT] = right;
		face[DICELEFT] = left;
		face[DICEBACK] = back;
		face[DICEBOTTOM] = bottom;
	}
	~Dice( ) {
		delete [ ] face;
	}
	void setDice( int top, int front, int right, int left, int back, int bottom ) {
		if( 0 < sizeof( face )/sizeof( face[0] ) ) {
			face[DICETOP] = top;
			face[DICEFRONT] = front;
			face[DICERIGHT] = right;
			face[DICELEFT] = left;
			face[DICEBACK] = back;
			face[DICEBOTTOM] = bottom;
		}
		return;
	}
	void roll( string cmd ) {
		int t;
		for( int i=0; i<cmd.length(); i++ ) {
			if( 'E' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICELEFT];
				face[DICELEFT] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICERIGHT];
				face[DICERIGHT] = t;
			} else if( 'N' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICEFRONT];
				face[DICEFRONT] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICEBACK];
				face[DICEBACK] = t;
			} else if( 'S' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICEBACK];
				face[DICEBACK] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICEFRONT];
				face[DICEFRONT] = t;
			} else if( 'W' == cmd[i] ) {
				t = face[DICETOP];
				face[DICETOP] = face[DICERIGHT];
				face[DICERIGHT] = face[DICEBOTTOM];
				face[DICEBOTTOM] = face[DICELEFT];
				face[DICELEFT] = t;
			} else if( 'M' == cmd[i] ) {
				t = face[DICEBACK];
				face[DICEBACK] = face[DICERIGHT];
				face[DICERIGHT] = face[DICEFRONT];
				face[DICEFRONT] = face[DICELEFT];
				face[DICELEFT] = t;
			}
		}
		return;
	}
	int getFace( int diceface ) {
		return face[ diceface ];
	}
};

int main( )
{
	int t, f, r, l, ba, bo;
	cin>>t>>f>>r>>l>>ba>>bo;
	Dice *dice = new Dice( t, f, r, l, ba, bo );

	cin>>t>>f>>r>>l>>ba>>bo;
	Dice *dice2 = new Dice( t, f, r, l, ba, bo );
	
	int i, cnt;
	cnt = 0;
	while( cnt <= DICEBOTTOM ) {
		switch( cnt ) {
			case DICETOP:
					cnt++;
				break;
			case DICEFRONT:
					dice2->roll( "N" );
					cnt++;
				break;
			case DICERIGHT:
					dice2->roll( "W" );
					cnt++;
				break;
			case DICELEFT:
					dice2->roll( "E" );
					cnt++;
				break;
			case DICEBACK:
					dice2->roll( "S" );
					cnt++;
				break;
			case DICEBOTTOM:
					dice2->roll( "SS" );
					cnt++;
				break;
			}
			if( dice2->getFace( DICETOP ) == dice->getFace( DICETOP ) ) {
				for( i=0; i<3; i++ ) {
					if( dice2->getFace( DICEFRONT ) == dice->getFace( DICEFRONT ) ) { break; }
					dice2->roll( "M" );
				}
				for( i=0; i<6; i++ ) {
					if( dice2->getFace( i ) != dice->getFace( i ) ) { break; }
				}
				if( DICENUM == i ) { break; }
			}
			dice2->setDice( t, f, r, l, ba, bo );
	}
	if( DICENUM == i ) { 
		cout<<"Yes"<<endl;	
	} else {
		cout<<"No"<<endl;
	}

	delete dice;
	delete dice2;
	
	return 0;
}

Measured memory_bytes: 1208
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

int main(void)
{
    int k, a, b;

    cin >> k >> a >> b;

    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            cout << "OK" << endl;
            return 0;
        }
    }

    cout << "NG" << endl;
}


Measured memory_bytes: 3624
x, k, d = map(int, input().split())
x = abs(x)

need, mod = divmod(x, d)
if k <= need:
    ans = x - k*d
else:
    amari = k - need
    if amari % 2 == 0:
        ans = mod
    else:
        ans = mod - d


print(abs(ans))

Measured memory_bytes: 9136
n,m=[int(i) for i in input().split()]

x=[int(i) for i in input().split()]

x.sort()

sa=[]

for i in range(1,m):
    sa.append(x[i]-x[i-1])

sa.sort()

ans=0

for i in range(max(0,m-n)):
    ans+=sa[i]
print(ans)

Measured memory_bytes: 19964
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

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

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k;
    cin >> s >> k;
    ll cnt = 0;
    ll n = s.size();
    set<char> se;
    for (int i = 0; i < n; i++)
    {
        se.insert(s[i]);
    }
    if (se.size() == 1)
    {
        cout << (n * k) / 2 << endl;
        return 0;
    }
    for (ll i = 0; i < n - 1; i++)
    {
        if (s[i] == s[i + 1])
        {
            cnt++;
            i++;
        }
    }
    string t = s + s;
    n = t.size();
    ll cnt2 = 0;
    for (ll i = 0; i < n - 1; i++)
    {
        if (t[i] == t[i + 1])
        {
            cnt2++;
            i++;
        }
    }
    ll ans = (ll)cnt + (cnt2 - cnt) * (k - 1);
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>

using namespace std;
vector <pair <int, int> > edges[100000];
int diameter;
bool used[100000];
int dfs(int cur_node){
    used[cur_node] = true;
    vector <int> dists;
    for(int i = 0; i < edges[cur_node].size(); i++){
       int next_node = edges[cur_node][i].first;
       int next_weight = edges[cur_node][i].second;
       if(!used[next_node]){
        dists.push_back(next_weight + dfs(next_node));
       } 
    }

    sort(dists.begin(), dists.end());
    if(dists.size() >= 2){
        diameter = max(diameter, dists[dists.size() - 1] + dists[dists.size() - 2]);
    }

    if(dists.size() == 0){
        return 0;
    }  
    return *max_element(dists.begin(), dists.end());
}
int main(){
    int n;
    cin >> n;

    for(int i = 0; i < n - 1; i++){
        int s;
        int t;
        int w;
        cin >> s >> t >> w;
        edges[s].push_back(make_pair(t, w));
        edges[t].push_back(make_pair(s, w));
    }

    diameter = max(diameter, dfs(0));
    cout << diameter << endl;

    return 0;
}



Measured memory_bytes: 17924
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int g[13] = {};
  g[1] = g[3] = g[5] = g[7] = g[8] = g[10] = g[12] = 1;
  g[4] = g[6] = g[9] = g[11] = 2;
  g[2] = 3;

  int x, y;
  cin >> x >> y;

  if (g[x] == g[y])
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

class SCC {
public:
    explicit SCC(const vector<vector<int>>& g) : idx(g.size(), -1) {
        const int N = g.size();
        vector<int> order, visit(N, 0);
        for(int i=0;i<N;i++){
            if(!visit[i]) dfs(i, g, order, visit);
        }
        reverse(order.begin(), order.end());
        vector<vector<int>> h(g.size());
        for(int i=0;i<g.size();i++){
            for(auto& t : g[i]) h[t].push_back(i);
        }
        int s = 0;
        for(auto& t : order){
            if(idx[t] != -1) continue;
            compS.push_back(vector<int>());
            dfs2(t, h, s);
            ++s;
        }
        compG.assign(s, vector<int>());
        for(int i=0;i<N;i++){
            for(auto& t : g[i]){
                if(idx[i] != idx[t]) compG[idx[i]].push_back(idx[t]);
            }
        }
    }
    const auto& getGraph() const { return compG; }
    int getCompNum() const { return compG.size(); }
    int getId(int v) const { return idx[v]; }
    const auto& getConnectSet(int id) const { return compS[id]; }
private:
    void dfs(int pos, const vector<vector<int>>& g, vector<int>& order, vector<int>& visit){
        visit[pos] = 1;
        for(auto& t : g[pos]){
            if(visit[t]) continue;
            dfs(t, g, order, visit);
        }
        order.push_back(pos);
    }
    void dfs2(int pos, const vector<vector<int>>& g, int id){
        idx[pos] = id;
        compS[id].push_back(pos);
        for(auto& t : g[pos]){
            if(idx[t] != -1) continue;
            dfs2(t, g, id);
        }
    }
private:
    vector<vector<int>> compG;
    vector<int> idx;
    vector<vector<int>> compS;
};

vector<int> topologicalSort(const vector<vector<int>>& g){
    vector<int> deg(g.size(), 0);
    for(auto& v : g){
        for(auto& t : v) ++deg[t];
    }
    vector<int> res;
    for(int i=0;i<g.size();i++) if(!deg[i]) res.push_back(i);
    for(int i=0;i<g.size();i++){
        for(auto& t : g[res[i]]){
            --deg[t];
            if(!deg[t]) res.push_back(t);
        }
    }
    return res;
}

int main(){
    int N, M; cin >> N >> M;
    vector<vector<int>> g(N);
    for(int i=0;i<M;i++){
        int a, b; cin >> a >> b;
        g[a].push_back(b);
    }
    SCC scc(g);
    auto order = topologicalSort(scc.getGraph());
    cout << order.size() << endl;
    for(auto& s : order){
        auto& v = scc.getConnectSet(s);
        cout << v.size();
        for(auto& t : v) cout << " " << t;
        cout << endl;
    }
}

Measured memory_bytes: 101384
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

//mod演算ライブラリ
//mod=1000000007

LL add(LL a,LL b){
  return (a+b)%mod;
}

LL sub(LL a,LL b){
  return (a+mod-b)%mod;
}

LL mul(LL a,LL b){
  return ((a % mod) * (b % mod)) % mod;
}

LL power(LL x,LL y){//繰り返し二乗法 単品利用可
  if(y==0)return 1;
  else if(y==1)return x%mod;
  else if(y%2==0){
    LL tmp=power(x, y/2) % mod;
    return tmp*tmp%mod;
  }else {
    LL tmp=power(x, y/2) % mod;
    return ((tmp*tmp)%mod)*x%mod;
  }
}

LL dvs(LL a,LL b){
  return mul(a,power(b,mod-2));
}

const int SIZE_mod=200005;
int invfact[SIZE_mod];
int fact[SIZE_mod];

LL factset(int a){//aまでの階乗%mod表を作成
  fact[0]=1;
  FORQ(i,1,a){
    fact[i]=mul(fact[i-1],i);
  }
}

LL cmbset(int a){//1~aまでの階乗と階乗数の逆元のmod(mod)を用意 O(a)
  factset(a);
  invfact[a]=power(fact[a],mod-2);
  invfact[0]=1;
  FORD(i,a,1){
    invfact[i]=mul(invfact[i+1],i+1);
  }

}

LL cmb(int n,int r){//nCr%mod  (cmbset後に使用)
  if(n<r||r<0||n<0)return 0;
  return mul(fact[n],mul(invfact[r],invfact[n-r]));
}

LL prm(int n,int r){//nPr%mod
    return mul(cmb(n,r),fact[n]);
}

LL homo(int n,int r){//nHr%mod
  return cmb(n+r-1,r);
}



int prime[100002]={};
int Er_N=100001;
void Er(){//Eratosthenes  1:PRIME  0:NOT PRIME
	for(int i = 2; i < Er_N; i++){
		prime[i] = 1;
	}
	int limit_Er_roop=sqrt(Er_N);
	for(int i = 2; i < limit_Er_roop; i++){
		if(prime[i]){
			for(int j = 0; i * (j + 2) < Er_N; j++){
				prime[i *(j + 2)] = 0;
			}
		}
	}
}


int main(){
	LL n,a[1111]={};
	cin>>n;
	FORQ(i,2,n){
		int t=i;
		FORQ(j,2,n){
			while(t%j==0){
				t/=j;
				a[j]++;
			}
		}
	}
	LL ans=1;
	FORQ(i,2,n){
		//cerr<<i<<" "<<a[i]<<endl;
		ans=mul(ans,a[i]+1LL);
	}
	cout<<ans;
    return 0;
}


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


int main()
{
        string s;
        cin>>s;
        vector< int > v;
        for(auto x: s){
                v.push_back( x-'0' );
        }

        for(int i = 0; i < 8; i++) {
                int a = ( i & (1) );
                int b = (bool)  (i & (2) );
                int c = (bool) ( i & 4);
                vector<int> low = {a, b, c};

                int tot = v[0];
                int cnt = 1;
                for(auto x : low) {
                        if( x ) tot += v[cnt];
                        else tot -= v[cnt];
                        cnt++;
                }

                if(tot == 7) {
                        cout << v[0];
                        int pos = 1;
                        for(auto x : low) {
                                if(x) cout << "+";
                                else cout << "-";
                                cout << v[pos];
                                pos++;
                        }
                        cout << "=7\n";
                        return 0;
                }


        }


        return 0;
}


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

using namespace std;
using ll = long long;

void erasedot(vector<vector<char> > &m, int &H, int &W) {
    for(int i = 0; i < H; i++) {
        bool check = 1;
        for(int j = 0; j < W; j++) {
            if(m.at(i).at(j) == '#') {
                check = 0;
                break;
            }
        }
        if(check) {
            m.erase(m.begin() + i);
            i--;
            H--;
        }
    }
    return;
}
void changehw(vector<vector<char> > &m, int &H, int &W) {
    vector<vector<char> > tempm(W, vector<char>(H));
    int tempH = H, tempW = W;

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            tempm.at(j).at(i) = m.at(i).at(j);
        }
    }
    H = tempW;
    W = tempH;
    m = tempm;

    return;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char> > m(H,vector<char>(W));

    for(int i = 0; i < H; i++) {
        string S;
        cin >> S;
        for(int j = 0; j < W; j++) {
            m.at(i).at(j) = S.at(j);
        }
    }
    erasedot(m, H, W);
    changehw(m, H, W);
    erasedot(m, H, W);
    changehw(m, H, W);
    

    for(int i = 0; i < H; i++) {
        for(int j = 0; j < W; j++) {
            cout << m.at(i).at(j);
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int X = sc.nextInt();
		int A = sc.nextInt();
		int B =sc.nextInt();
		if ((A*10+B)%4==0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <unordered_map>
#define sp ' '
#define nyan "(=^・ω・^=)"
#define mkp make_pair
#define intmax 2147483647
#define llmax 9223372036854775807
#define lP pair<ll,ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;
const int mod=1000000007;

int N, K, a[100000];
ll s[100001], k[100001], res;

int main() {
	cin >> N >> K;
	for (int i = 0; i != N; ++i)
		cin >> a[i];
	for (int i = 1; i != N + 1; ++i) {
		s[i] = s[i - 1] + a[i - 1];
		k[i] = k[i - 1] + max(a[i - 1], 0);
	}
	for (int i = 0; i != N - K + 1; ++i) {
		res = max(res, k[N] - (k[i + K] - k[i]) + max(s[i + K] - s[i], 0ll));
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <complex>
#include <bitset>
#include <functional>

using namespace std;
using ll=long long int;

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    const double pi = acos(-1);
    const double eps = 1e-11;
    double c = a*a*b;

    double l, r;
    if (x > c/2) {
        l = 0; r = atan2(b, a);
        while (r - l > eps) {
            double mid = (l+r)/2;
            if (c - x >= a*a*(a*tan(mid))/2) {
                l = mid;
            } else {
                r = mid;
            }
        }
    } else {
        l = atan2(b, a); r = pi/2;
        while (r - l > eps) {
            double mid = (l+r)/2;
            if (b * (b / tan(mid)) * a / 2 >= x) {
                l = mid;
            } else {
                r = mid;
            }
        }
    }

    cout << fixed << setprecision(20);
    cout << l * (180 / pi) << endl;

    return 0;
}


Measured memory_bytes: 256
def LI():
    return list(map(int, input().split()))


H, W, A, B = LI()
S = "1"*A+"0"*(W-A)
for _ in range(B):
    print(S)
S = "0"*A+"1"*(W-A)
for _ in range(H-B):
    print(S)


Measured memory_bytes: 9180
import std.stdio,std.string,std.array,std.algorithm,std.range,std.conv;

int main(){
    auto s=readln.chomp;
    auto n=s.length;
    if(s==s.rev){
        auto s1=s.dup[0..(n-1)/2];
        if(s1==s1.rev){
            auto s2=s.dup[(n+3)/2-1..$];
            if(s2==s2.rev){
                "Yes".writeln;
                return 0;
            }
        }
    }   
    "No".writeln;
    return 0;
}

auto rev(const char[] s){ 
    auto ss=s.dup;
    foreach(i;0..ss.length/2){
        ss[i]=ss[$-i-1];
    }   
    return ss; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >> n;
  int a[n+2];
  ll ans=0;
  a[0]=0,a[n+1]=0;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    ans+=abs(a[i]-a[i-1]);
    if(i==n)ans+=abs(a[n+1]-a[n]);
  }
  for(int i=1;i<=n;i++){
    if(a[i-1]<=a[i] && a[i]<=a[i+1] || a[i-1]>=a[i] && a[i]>=a[i+1]){cout << ans << endl;}
    else{cout << ans-2*min(abs(a[i-1]-a[i]),abs(a[i]-a[i+1])) << endl;}
  }

}

Measured memory_bytes: 3988
use proconio::fastout;
use whiteread::parse_line;

#[fastout]
fn main() {
    let n: usize = parse_line().unwrap();
    let k: usize = parse_line().unwrap();
    let x: usize = parse_line().unwrap();
    let y: usize = parse_line().unwrap();

    let mut price = n * x;
    if n > k {
        price -= (n - k) * (x - y);
    }
    println!("{}", price);
}


Measured memory_bytes: 2204
n = gets.to_i
n.times do
    xa, ya, ra, xb, yb, rb = gets.split.map(&:to_f)
    d = Math::hypot(xa - xb, ya - yb)
    if d < ra - rb
        puts 2
    elsif d < rb - ra
        puts -2
    elsif d > ra + rb
        puts 0
    else
        puts 1
    end
end


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

using namespace std;

int calc(vector<int> cup, int m)
{
    int cnt = 0;
    while (1) {
        int i = cnt%2, j = i+1;
        int p = 1;
        while (p <= max(cup[i], cup[j])) p <<= 1;
        p >>= 1;
        if (!p) break;
        cup[i] ^= p;
        cup[j] ^= p;
        cnt++;
        if (cnt > m) return cnt;
    }

    return cnt;
}

int main()
{
    while (1) {
        int n, m; cin >> n >> m;
        if (n == 0 && m == 0) break;
        vector<int> cup(3);
        loop (3, i) {
            int c; cin >> c;
            while (c--) {
                int v; cin >> v;
                cup[i] |= 1 << v--;
            }
        }
        int ans = calc(cup, m);
        swap(cup[0], cup[2]);
        ans = min(ans, calc(cup, m));
        cout << (ans <= m ? ans : -1) << endl;
    }
    return 0;
}

Measured memory_bytes: 1208
#include "bits/stdc++.h"
using namespace std;

/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
int main() {
	string s;
	cin >> s;
	long long int k;
	cin >> k;
	char t = s[s.size() - 1];
	string c = s;
	long long int cnt = 0;
	if (s.size() == 1) {
		cout << k / 2;
		return 0;
	}
	for (int i = 0; i < s.size()-1;i++) {
		if (s[i] != s[i + 1]) {
			break;
		}
		if (i == s.size() - 2) {
			cout << s.size()*k / 2;
			return 0;
		}
	}
	if (k != 1) {
		if (s[0] != t) {
			t = s[0];
			for (int i = 1; i < s.size(); i++) {
				if (t == s[i]) {
					cnt++;
					s[i] = '0';
				}
				t = s[i];
			}
			cout << cnt * k;
		}
		else {
			t = s[0];
			for (int i = 1; i < s.size(); i++) {
				if (t == s[i]) {
					cnt++;
					s[i] = '0';
				}
				t = s[i];
			}
			long long int bcnt = 0;
			char b = s[s.size()-1];
			for (int i = 0; i < c.size(); i++) {
				if (b == c[i]) {
					bcnt++;
					c[i] = '0';
				}
				b = c[i];
			}
			cout << cnt+(k-1)*bcnt;
		}
	}
	else {
		t = s[0];
		for (int i = 1; i < s.size(); i++) {
			if (t == s[i]) {
				cnt++;
				s[i] = '0';
			}
			t = s[i];
		}
		cout << cnt;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
using namespace std;
 
int main(){
    
    int i[3],K,ans;

    for(int j=0;j<3;j++){
        cin >> i[j];
    }
    sort(i,i+3);
    cin>> K;

    for(int k=1;k<=K;k++){
        i[2]= i[2]*2;
    }

    ans = i[0] + i[1] + i[2];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...)name
#define _rep(i,n)repi(i,0,n)
#define repi(i,a,b)for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x)x
#define rep(...)MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c)c.begin(),c.end()
#define write(x)cout<<(x)<<'\n'
using namespace std; using ll = long long; template<class T>using vv = vector<vector<T>>;
template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
constexpr int INF = 1 << 29, MOD = 998244353; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

ll mpow(ll x, ll n) { ll y = 1; for (; n; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }

int main() {
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    const ll inv2 = mpow(2, MOD - 2);

    vv<ll> dp = vvec(N + 1, 6e3, 0LL);
    dp[0][0] = 1;

    rep(i, N) {
        rep(j, S + 1) {
            dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % MOD;
            dp[i + 1][j + A[i]] = (dp[i + 1][j + A[i]] + dp[i][j] * inv2) % MOD;
        }
    }

    write(dp[N][S] * mpow(2, N) % MOD);
}

Measured memory_bytes: 144144
let readInt _ = stdin.ReadLine() |> int

seq {
    yield 2L
    yield 1L
    yield! Seq.unfold (fun (a, b) -> Some(a + b, (b, a + b))) (2L, 1L)
}
|> Seq.skip (readInt ())
|> Seq.head
|> printfn "%d"


Measured memory_bytes: 30124
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <cassert>
#include <fstream>
#include <iomanip>

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

const ll mod = 1e9 + 7;

vector<ll> dx = {1, -1, 0, 0};
vector<ll> dy = {0, 0, 1, -1};

vector<vector<ll>> g;


int main() {
    
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    string s;
    cin >> s;
    
    ll ret = 0;
    
    for (int i = 1; i < s.size(); ++i)
    {
        if (s[i] != s[i - 1])
        {
            ret++;
        }
    }
    
    cout << ret << endl;
    
    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); ++i)
#define fi first
#define se second
#define INF 1000000009
#define LLINF 1000000000000000009LL
using ll = long long;
using P = pair<char, char>;

int main(){
  int n,q;
  string s;
  cin>>n>>q>>s;
  vector<P>a(q);
  rep(i,q){
    cin>>a[i].fi>>a[i].se;
  }

  auto judge=[&](ll mid){
    int now=mid;
    rep(i,q){
      if(s[now]==a[i].fi){
        if(a[i].se=='L')now--;
        else now++;
      }
      if(now<0)return false;
      if(now>=n)return true;
    }
    return true;
  };
  auto bs=[&](){
    ll l=-1,r=n;
    while(r-l>1){
      ll mid=(l+r)/2;
      if(judge(mid)){
        r=mid;
      }
      else{
        l=mid;
      }
    }
    return r;
  };

  auto judge2=[&](ll mid){
    int now=mid;
    rep(i,q){
      if(s[now]==a[i].fi){
        if(a[i].se=='L')now--;
        else now++;
      }
      if(n<=now)return false;
      if(now<0)return true;
    }
    return true;
  };
  auto bs2=[&](){
    ll l=-1,r=n;
    while(r-l>1){
      ll mid=(l+r)/2;
      if(judge2(mid)){
        l=mid;
      }
      else{
        r=mid;
      }
    }
    return l;
  };
  int nl=bs();
  int nr=n-bs2()-1;
  cout<<n-nl-nr<<endl;
  return(0);
}


Measured memory_bytes: 900
#include <cstdio>
using namespace std;
const int maxn = 1e5+5;
int d[maxn];
int n;
int main(){
//freopen("input.txt", "r", stdin);
    while(scanf("%d", &n) == 1){
        for(int i = 0; i < n; i++)
            scanf("%d", &d[i]);
        bool fg1;
        if(n == 1)
        {
            printf("1\n");
            continue;
        }
        int ans = 0;
        int len = 1;
        
        for(int i = 1; i < n; i++)
        {
            if(len == 1) 
            {
                int t  = d[i] - d[i-1];
                if(t == 0) continue;
                else fg1 = (t > 0) ? true: false;
            }
            if(fg1 == true) 
            {
                if(d[i] >= d[i-1]) len++; 
                else{
                    fg1 = false;
                    if(len > 1){ans++; len = 1;}
                }
            }
            else{
                if(d[i] <= d[i-1]) len++;
                else{
                    fg1 = true;
                    if(len > 1){ans++; len = 1;}
                }
            }
        }
        printf("%d\n", ans+1);
    }
    return 0;
}

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

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define REP(i,n) for(int _n=n, i=0;i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)
#define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i)
#define trav(a, x) for (auto& a : x)
using ull = uint64_t;
using ll = int64_t;
using PII = pair<int, int>;
using VI = vector<int>;
#define INF (1ll<<60)

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template <typename A> string to_string(A v) {
bool first = true; string res = "{";
for (const auto &x : v) { if (!first) { res += ", "; } first = false; res += to_string(x); }
res += "}"; return res; }
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H); debug_out(T...); }
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)


int main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int H, W, D;
    cin >> H >> W >> D;
    vector<VI> grid(H + 2, VI(W + 2));
    // unordered_map<int, PII> M;
    PII M[H * W + 2];
    FOR(i, 1, H) {
        FOR(j, 1, W) {
            cin >> grid[i][j];
            M[grid[i][j]] = {i, j};
        }
    }
    VI sum(H * W + 2);
    FOR(i, 1, D) {
        sum[i] = 0;
        FOR(j, i + D, H * W) {
            int x1 = M[j - D].first, y1 = M[j - D].second;
            int x2 = M[j].first, y2 = M[j].second;
            int cost = abs(x2 - x1) + abs(y2 - y1);
            sum[j] = sum[j - D] + cost;
        }
    }
    int Q;
    cin >> Q;
    while (Q--) {
        int L, R;
        cin >> L >> R;
        cout << sum[R] - sum[L] << '\n';
    }
}

Measured memory_bytes: 2560
#include <stdio.h>

int N, A[212][3];
bool ok[212];
int ans[212];

int main(void) {
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) { scanf("%d%d%d", &A[i][0], &A[i][1], &A[i][2]); }

	for (int i = 0; i < N; ++i) { ok[i] = true; }
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < N; ++j) {
			for (int k = 0; k < N; ++k) {
				if (k != j) {
					if (A[j][i] == A[k][i]) { ok[j] = false; ok[k] = false; }
				}
			}
			if (ok[j] == true) { ans[j] += A[j][i]; }
		}
		for (int j = 0; j < N; ++j) { ok[j] = true; }
	}

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

Measured memory_bytes: 2688
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
S=SR()

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


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

int main(){
  int n;
  cin>>n;
  
  bool a=false;
  int ans;
  for(int i=1;i<=n;i++){
    if(i*1.08>=n&&i*1.08-n<1){
      a=true;
      ans=i;
    }
  }
  if(a){
    cout<<ans<<endl;
  }else{
    cout<<":("<<endl;
  }
}

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

int main(){
	int n;
	cin >> n;
	char s[n],t[n];
	cin >> s;
	cin >> t;

	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			if(s[i]==t[j]){
				for(int k=0; s[i+k]!='\0'; k++){
					if(s[i+k]!=t[j+k]){
						break;
					}
					if(s[i+k+1]=='\0'){
						cout << i+n << endl;
						return 0; 
					}
				}
			}
		}
	}
	cout << n*2 << endl;
	return 0;
}

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

int main(){
    int N;
    int f,l;
    cin >> N;
    int ans=0;
    vector<vector<int>> c(9, vector<int>(9, 0));
    for (int i=0; i<9; i++){
        for (int j=0; j<9; j++){
            for (int k=1; k<=N; k++){
                l = k%10;
                f = k;
                while (f >= 10) f=f/10;
                if (f==i+1 && l==j+1) c.at(i).at(j)++;
            }
        }
    }
    for (int i=0; i<9; i++){
        for (int j=0; j<9; j++){
            ans = ans + c.at(i).at(j)*c.at(j).at(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int N;
    cin>>N;
    vector<int> x(N);
    for (int &t: x)
        cin>>t;
    int L;
    cin>>L;
    
    int D = 1;
    while ((1<<D) < N-1)
        D++;
    vector<vector<int>> T(N, vector<int>(D+1));

    int s = 0;
    int t = 1;
    int l = x[1]-x[0];
    while (s<N-1)
    {
        if (t<N-1 && l+x[t+1]-x[t] <= L)
        {
            l += x[t+1]-x[t];
            t++;
        }
        else
        {
            l -= x[s+1]-x[s];
            T[s][0] = t-s;
            s++;
        }
    }

    for (int d=1; d<=D; d++)
        for (int i=0; i<N; i++)
            T[i][d] = T[i][d-1] + T[i+T[i][d-1]][d-1];

    //for (int j=0; j<=D; j++)
    //{
    //    for (int i=0; i<N; i++)
    //        cout<<" "<<T[i][j];
    //    cout<<endl;
    //}

    int Q;
    cin>>Q;
    for (int q=0; q<Q; q++)
    {
        int a, b;
        cin>>a>>b;
        a--, b--;
        if (a>b)
            swap(a, b);
        int ans = 0;

        while (a<b)
        {
            int d = 0;
            while (a+T[a][d] < b)
                d++;
            if (d>0)
                d--;
            ans += 1<<d;
            a += T[a][d];
        }
        cout<<ans<<endl;
    }
}


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

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

    vector<long long int> a(N);
    long long int y = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        y += a[i];
    }

    long long int x = 0;
    long long int min = LLONG_MAX;

    for (int i = 0; i < N - 1; i++) {
        x += a[i];
        y -= a[i];
        // cout << x << " " << y << endl;

        if (abs(x - y) < min) {
            min = abs(x - y);
        }
    }
    cout << min << endl;

    return 0;
}


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

using namespace std;

int n,q,head[200010],num_edge,bj[200010];
long long int val[200010];

struct edge
{
	int next;
	int to;
}E[500010];

void DFS(int now)
{
	bj[now]=1;
	if(head[now]==0)
	    return;
	for(int i=head[now];i>0;i=E[i].next)
	{
		if(bj[E[i].to]==0)
		{
			val[E[i].to]=val[E[i].to]+val[now];
			DFS(E[i].to);
		}
	}
	return;
}

int main()
{
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n-1;i++)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		num_edge++;
		E[num_edge].next=head[a];
		E[num_edge].to=b;
		head[a]=num_edge;
		num_edge++;
		E[num_edge].next=head[b];
		E[num_edge].to=a;
		head[b]=num_edge;
	}
	for(int i=1;i<=q;i++)
	{
		int p;
		long long int a;
		scanf("%d%lld",&p,&a);
		val[p]=val[p]+a;
	}
	DFS(1);
	for(int i=1;i<=n;i++)
	    printf("%lld ",val[i]);
	printf("\n");
	return 0;
}

Measured memory_bytes: 15616
import sys
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N =int(input())
    A = list(map(int,input().split()))

    count =0
    for i in range(N):
        if i%2==0 and A[i]%2 ==1:
            count +=1


    print(count)





if __name__ == "__main__":
    main()


Measured memory_bytes: 9116