akhauriyash/Code-Regression huggingface dataset:
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	Scanner sc;

	void run() {
		for (;;) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if ((a | b) == 0) {
				break;
			}

			int memo[] = new int[b];
			int first = a;
			int count = 0;
			int v1 = 0;
			int vv = 0;
			for (;;) {
				count++;
				if (memo[first] != 0) {
					v1 = memo[first] - 1;
					vv = count - memo[first];
					if(first ==0){
						vv = 0;
					}
					break;
				}
				memo[first] = count;
				first = first * 10;
				int v = first / b;
				int v2 = first % b;
				first = v2;

			}
			System.out.println(v1 + " " + vv);
		}
	}

	/**
	 * @param args
	 */

	Main() {
		sc = new Scanner(System.in);
		try {
			sc = new Scanner(new File(""));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			// e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}

Measured memory_bytes: 20000
S=input()
flag=0
if S[0]=="A":
    flag+=1
if ord(S[1])<97:
    flag=-1
for i in S[2:-1]:
    if i=="C":
        flag+=1
    elif ord(i)<97:
        flag=-1
if ord(S[-1])<97:
    flag=-1
if flag==2:
    print("AC")
else:
    print("WA")


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

template<class T> void chmin(T &a, T b) {
    if (a > b) a = b;
}

const long long INF = 1LL<<60;

int main() {
    int N; cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; ++i) cin >> h[i];
    
    vector<long long> dp(N, INF);
    dp[0] = 0;
    
    for (int i = 0; i < N; ++i) {
        if (i + 1 < N) {
            chmin(dp[i + 1], dp[i] + abs(h[i] - h[i+1]));
        }
        if (i + 2 < N) {
            chmin(dp[i + 2], dp[i] + abs(h[i] - h[i+2]));
        }
    }
    
    cout << dp[N-1] << endl;
}

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

using namespace std;

const int MAXV = 10000100;

bool np[MAXV];

void precalc() {
   np[0] = np[1] = true;
   for (int i = 2; i < MAXV; ++i) {
      if (np[i]) continue;
      for (int j = i + i; j < MAXV; j += i) {
         np[j] = true;
      }
   }
}

int main() {
   ios_base::sync_with_stdio(false);
   precalc();
   int N;
   cin >> N;
   vector<int> X(N);
   for (int i = 0; i < N; ++i) {
      cin >> X[i];
   }
   {
      vector<int> newX;
      newX.emplace_back(X[0]);
      for (int i = 0; i + 1 < N; ++i) {
         if (X[i] + 1 != X[i + 1]) {
            newX.emplace_back(X[i] + 1);
            newX.emplace_back(X[i + 1]);
         }
      }
      newX.emplace_back(X.back() + 1);
      X = newX;
      N = X.size();
   }
   vector<int> odds;
   vector<int> evens;
   for (int i = 0; i < N; ++i) {
      if (X[i] & 1) {
         odds.emplace_back(X[i]);
      } else {
         evens.emplace_back(X[i]);
      }
   }
   int no = odds.size();
   int ne = evens.size();
   vector<vector<int>> adj(no);
   vector<int> mt(ne, -1);
   vector<int> visited(no);
   for (int i = 0; i < no; ++i) {
      for (int j = 0; j < ne; ++j) {
         if (!np[abs(odds[i] - evens[j])]) {
            adj[i].emplace_back(j);
         }
      }
   }
   int tt = 0;
   function<bool(int)> dfs = [&](int v) {
      if (visited[v] == tt) return false;
      visited[v] = tt;
      for (int u : adj[v]) {
         if (mt[u] == -1) {
            mt[u] = v;
            return true;
         }
      }
      for (int u : adj[v]) {
         if (dfs(mt[u])) {
            mt[u] = v;
            return true;
         }
      }
      return false;
   };
   int ans = 0;
   for (int i = 0; i < no; ++i) {
      ++tt;
      ans += dfs(i);
   }
   no -= ans;
   ne -= ans;
   ans += 2 * (no / 2);
   ans += 2 * (ne / 2);
   if (no & 1) ans += 3;
   cout << ans << "\n";
   return 0;
}


Measured memory_bytes: 10112
import sys
sys.setrecursionlimit(10**7)


class SCC:
    def __init__(self,N):
        self.N = N
        self.graph = [[] for _ in range(N)]
        self.graph_rev = [[] for _ in range(N)]
        self.flag = [False]*N

    def add_edge(self,start,end):
        if start == end:
            return
        self.graph[start].append(end)
        self.graph_rev[end].append(start)

    def dfs(self,node,graph):
        self.flag[node] = True
        for n in graph[node]:
            if self.flag[n]:
                continue
            self.dfs(n,graph)
        self.order.append(node)

    def first_dfs(self):
        self.flag = [False]*self.N
        self.order = []
        for i in range(self.N):
            if self.flag[i] == False:
                self.dfs(i,self.graph)

    def second_dfs(self):
        self.flag = [False]*self.N
        self.ans = []
        for n in reversed(self.order):
            if self.flag[n]:
                continue
            self.flag[n] = True
            self.order = []
            self.dfs(n,self.graph_rev)
            self.order.reverse()
            self.ans.append(self.order)

    def scc(self):
        self.first_dfs()
        self.second_dfs()
        return self.ans


class Two_SAT():
    def __init__(self,N):
        self.N = N
        self.e = [[] for _ in range(2*N)]

    def add_condition(self,start,bool_start,end,bool_end):  # start or end という条件を考える
        self.e[start*2+(bool_start^1)].append(end*2+bool_end)
        self.e[end*2+(bool_end^1)].append(start*2+bool_start)

    def satisfiable(self):
        scc = SCC(2*self.N)
        for i in range(2*self.N):
            for j in self.e[i]:
                scc.add_edge(i,j)
        C = scc.scc()
        I = [0]*(2*self.N)
        for i in range(len(C)):
            for j in C[i]:
                I[j] = i
        res = [0]*(2*self.N)
        for i in range(self.N):
            if I[2*i] == I[2*i+1]:
                return (False,res)
            if I[2*i] < I[2*i+1]:
                res[i] = 1
        return (True,res)


def MI(): return map(int,sys.stdin.readline().rstrip().split())


N,D = MI()
TS = Two_SAT(N)
XY = [tuple(MI()) for _ in range(N)]

for i in range(N-1):
    x1,y1 = XY[i]
    for j in range(i+1,N):
        x2,y2 = XY[j]
        if abs(x1-x2) < D:
            TS.add_condition(i,1,j,1)
        if abs(x1-y2) < D:
            TS.add_condition(i,1,j,0)
        if abs(y1-x2) < D:
            TS.add_condition(i,0,j,1)
        if abs(y1-y2) < D:
            TS.add_condition(i,0,j,0)

# 0:X,1:Y

bl,sa = TS.satisfiable()

if not bl:
    print('No')
else:
    print('Yes')
    print(*[XY[i][sa[i]] for i in range(N)],sep='\n')


Measured memory_bytes: 70140
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
// #define endl "\n"
#define MOD 1000000007

ll recurse(ll i, bool color, vector<vector<ll>>& adj, vector<vector<ll>>& dp, ll from) {
    
    if (dp[i][color] != -1) {
        return dp[i][color];
    }
    ll ans = 1;
    for (auto v: adj[i]) {
        if (v != from) {

            ll temp =  recurse(v, true, adj, dp, i);
            if (color) {
                temp = (temp + recurse(v, false, adj, dp, i)) % MOD;
            }
            ans = (ans * temp) %MOD;
        }
    }
    return dp[i][color] = ans;
    
}

int main(void) {
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    // cout.tie(NULL);
    ll n;
    cin >> n;
    vector<vector<ll>> adj (n+1);
    for (ll i = 0; i < n-1; i++) {
        ll a, b;
        cin >> a >> b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    vector<vector<ll>> dp (n+1, vector<ll> (2, -1));

    cout << (recurse(1, true, adj, dp, 0) + recurse(1, false, adj, dp, 0))%MOD << endl;
    

    return 0;
}

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

using namespace std;
typedef long long LL;
const LL mod=1e9+7;

LL modpow(LL x, LL n){
	LL r=1;
	while(n){
		if(n&1) r=r*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return r;
}

LL modinv(LL x){
	LL m=mod, u=1, v=0;
	while(m){
		LL t=x/m;
		x-=t*m; swap(x,m);
		u-=t*v; swap(u,v);
	}
	u%=mod;
	if(u<0) u+=mod;
	return u;
}

int main(){
  int N;
  cin >> N;
  vector<LL> A(N);
  rep(i,N) cin >> A[i];
  sort(A.begin(),A.end());
  vector<LL> Ac(N);
  rep(i,N) Ac[i]=A[i];
  LL A_Max=A[N-1];
  vector<LL> D(A_Max+1);
  rep(i,N){
    for(LL j=2; j*j<=A[i]; j++){
      int num=0;
      while(Ac[i]%j==0){
        Ac[i]/=j;
        num++;
      }
      if(D[j]<num) D[j]=num;
    }
    if(!D[Ac[i]]) D[Ac[i]]=1;
  }
  LL ans=0, lc=1;
  for(LL i=2; i<=A_Max; i++){
    lc*=modpow(i,D[i]);
    lc%=mod;
  }
  rep(i,N){
    ans+=lc*modinv(A[i]);
    ans%=mod;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 8192
# AGC037A - Dividing a String
def main():
    # can't restore but the number (ans) is correct
    # aaaaa -> a/aa/a a (3) <-> aa/a/aa (3)
    S = input()
    ans, prev, cur = 0, "", ""
    for s in S:
        cur += s
        if cur != prev:
            ans += 1
            prev, cur = cur, ""
    print(ans)


if __name__ == "__main__":
    main()

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

int main() {
  int N, L;
  cin >> N >> L;
  int ans = 0;
  if (L > 0) {
    for (int i = 1; i < N; i++) {
      ans += L+i;
    }
  }
  else if (L <= 0 && L+N-1 > 0) {
    for (int i = 0; i < N; i++) {
      ans += L+i;
    }
  }
  else {
    for (int i = 0; i < N-1; i++) {
      ans += L+i;
    }
  }
  cout << ans << endl;
}

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

int main(){
  int n, pos = 0;
  string s;
  vector<string> vs;
  std::cin >> n >> s;
  while(s[pos] == '0')pos++;
  s = s.substr(pos);
  for (int i = 0; s.length() != 0; i++) {
    while(i < s.length() - 1 and not(s[i] == '0' and s[i + 1] == '0'))i++;
    if(i < s.length() - 1)vs.push_back(s.substr(0, i));
    else vs.push_back(s);
    while(i < s.length() - 1 and not(s[i] == '0' and s[i + 1] == '1'))i++;
    if(i == s.length()) s = "";
    else s = s.substr(i + 1);
    i = 0;
  }
  int ans = 0;
  for (int i = 0; i < vs.size(); i++) {
    // std::cout << vs[i] << std::endl;
    vector<int> len;
    int l = 0;
    for (int j = 0; j < vs[i].size(); j++) {
      if(j < vs[i].size() and vs[i][j] == '1')l++;
      else if(j < vs[i].size() and vs[i][j] == '0')len.push_back(l), l = 0;
    }
    if(l != 0)len.push_back(l);
    // for (int i = 0; i < len.size(); i++) {
    //   std::cout << len[i] << " ";
    // }
    // std::cout << std::endl;
    vector<vector<int> > dp(3, vector<int>(len.size(), 0));
    //0:LEFT, 1:RIGHT, 2:NOT UASD
    for (int j = 0; j < len.size() - 1; j++) {
      for (int k = 0; k < 3; k++) {
        dp[2][j + 1] = max(dp[2][j + 1], dp[k][j]);
      }
      dp[0][j + 1] = max(dp[0][j + 1], dp[2][j] + len[j]);
      dp[1][j + 1] = max(dp[1][j + 1], dp[2][j] + len[j + 1]);
      
      //L -> L
      dp[0][j + 1] = max(dp[0][j + 1], dp[0][j] + len[j] - 1);
      //L -> R
      if(len[j] > 1)dp[1][j + 1] = max(dp[1][j + 1], dp[0][j] + len[j + 1]);
      //R -> R
      dp[1][j + 1] = max(dp[1][j + 1], dp[1][j] + len[j + 1] - 1);
    }
    int end = len.size() - 1;
    // std::cout << vs[i] << std::endl;
    // std::cout << max(dp[0][end], max(dp[1][end], dp[2][end])) << std::endl;
    ans += max(dp[0][end], max(dp[1][end], dp[2][end]));
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 4564
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define int long long
#define INF 10000000000
using namespace std;
 
typedef pair<int, int> Pii;
typedef pair<double, int> Pdi;
 
void readint(int N, vector<int> &a);
void readdouble(int N, vector<double> &a);
void readindex(int N, vector<int> &a);
 
signed main(){
 
    string S;
    cin >> S;

    int N = S.size();
    int mod = 1e9 + 7;

    vector<vector<int>> dp(4, vector<int>(N + 1, 0));

    dp[0][0] = 1;

    REP(i, N){
        if(S[i] == '?'){
            dp[0][i + 1] = (dp[0][i] * 3) % mod;
        }else{
            dp[0][i + 1] = dp[0][i];
        }
    }

    REP(k, 3){
        REP(i, N){
            int tmp = 0;
            if(S[i] == '?' || S[i] == (char)('A' + k)) tmp += dp[k][i];
            if(S[i] == '?'){
                tmp += dp[k + 1][i] * 3;
            }else{
                tmp += dp[k + 1][i];
            }

            dp[k + 1][i + 1] = tmp % mod;
        }
    }

    cout << dp[3][N];
 
    return 0;
}
 
 
 
 
 
 
 
 
void readint(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readdouble(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}
void readindex(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str()) - 1;
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str()) - 1;
}

Measured memory_bytes: 4352
n=int(input())
alist=list(map(int,input().split()))

xdic={}
ydic={}

for i,a in enumerate(alist):
    #xlist.append((i+1)+a)
    #ylist.append((i+1)-a)
    tmpx=(i+1)+a
    tmpy=(i+1)-a
    if tmpx in xdic:
        xdic[tmpx]=xdic[tmpx]+1
    else:
        xdic[tmpx]=1
    if tmpy > 0:
        if tmpy in ydic:
            ydic[tmpy]=ydic[tmpy]+1
        else:
            ydic[tmpy]=1

output=0
for y in ydic:
    if y in xdic:
        output+= xdic[y]*ydic[y]

print(output)


Measured memory_bytes: 41616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
int main() {
	int n;	cin >> n;
  	vector<int> p(n);	rep(i,n) cin >> p.at(i);
  	
  	int mx = 1000000;
  	int count = 0;
  	rep(i,n){
    	if(p.at(i) <= mx) count++;
      	mx = min(mx,p.at(i));
    }
  	cout << count << endl;
}


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

int main()
{
    int N, K, ans=0;
    cin >> N >> K;
    vector<int> p(N);
    for(int i=0;i<N;++i) cin >> p[i];
    sort(p.begin(), p.end());
    for(int i=0;i<K;++i)
    {
        ans += p[i];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1001001001;
const int mod = 1000000007;


int main() {
    string v;
    cin >> v;
    if(v[0] == v[1] && v[0] == v[2]){
        cout << "No" << endl;
    }else{
        cout << "Yes" <<endl;
    }
}


Measured memory_bytes: 256
function Main(input){
    sec=input.split("/n");
    sec=parseInt(sec);
    h=parseInt(sec/3600);
    m=parseInt((sec-h*3600)/60);
    s=sec-h*3600-m*60;
    console.log(h+':'+m+':'+s);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

long long q;
bool rev = 0;
string s, pre, suf;

int main() {
  cin >> s >> q;
  for(int i = 0; i < q; ++i) {
    int t;
    cin >> t;
    if(t == 1)
      rev = !rev;
    else {
      int f;
      string c;
      cin >> f >> c;
      --f;
      if(rev ^ f)
        suf += c;
      else
        pre += c;
    }
  }
  if(rev) {
    reverse(s.begin(), s.end());
    reverse(suf.begin(), suf.end());
    swap(suf, pre);
  }
  else
    reverse(pre.begin(), pre.end());
  cout << pre + s + suf << endl;
  return 0;
}

Measured memory_bytes: 1348
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
const int N=55,inf=1e9;
int n,a[N],mn=inf,mx=-inf,px,pn;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]>mx)
			mx=a[i],px=i;
		if(a[i]<mn)
			mn=a[i],pn=i;
	}
	printf("%d\n",2*n-1);
	if(abs(mx)>abs(mn))
	{
		for(int i=1;i<=n;i++)
			printf("%d %d\n",px,i);
		for(int i=1;i<n;i++)
			printf("%d %d\n",i,i+1);
	}
	else
	{
		for(int i=1;i<=n;i++)
			printf("%d %d\n",pn,i);
		for(int i=n-1;i>=1;i--)
			printf("%d %d\n",i+1,i);
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll T,i;cin>>T;
  REP(i,T){
    ll N,M,A,B;cin>>N>>M>>A>>B;
    cout<<floor_sum(N,M,A,B)<<endl;
  }
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
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; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }

const ll INF = 1e18;
int r, c, k;
ll dp[3010][3010][5];
vector< vector<ll> > item(3010, vector<ll>(3010, 0));

int main() {
    cin >> r >> c >> k;
    for(int i = 0; i < k; ++i) {
        ll cr, cc, cv; cin >> cr >> cc >> cv;
        cr--; cc--;
        item[cr][cc] = cv;
    }

    for(int i = 0; i <= r; ++i) {
        for(int j = 0; j <= c; ++j) {
            for(int l = 0; l <= 3; ++l) {
                dp[i][j][l] = -INF;
            }
        }
    }
    
    dp[0][0][0] = 0;
    for(int i = 0; i <= r; ++i) {
        for(int j = 0; j <= c; ++j) {
            for(int l = 0; l <= 2; ++l) {
                if(item[i][j] != 0) {
                    if(i+1 <= r) chmax(dp[i+1][j][0], dp[i][j][l]+item[i][j]);
                    if(j+1 <= c)chmax(dp[i][j+1][l+1], dp[i][j][l]+item[i][j]);
                }
                if(i+1 <= r) chmax(dp[i+1][j][0], dp[i][j][l]);
                if(j+1 <= c) chmax(dp[i][j+1][l], dp[i][j][l]);
            }
        }
    }

    ll ans = 0;
    for(int i = 0; i <= 3; ++i) chmax(ans, dp[r][c][i]);
    cout << ans << endl;
}

Measured memory_bytes: 426772
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n+1];
  for(int i=0;i<n;i++) cin>>a[i];
  a[n]=0;
  vector<int> f(n+2,1500000000);
  f[0]=0;
  for(int i=0;i<n-1;i++){
    f[i+1]=min(f[i+1],abs(a[i]-a[i+1])+f[i]);
    f[i+2]=min(f[i+2],abs(a[i]-a[i+2])+f[i]);
  }
  cout<<f[n-1];
}

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

import static java.lang.Integer.parseInt;

/**
 * Sunrise and Sunset
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int H, R;
		H = parseInt(line.substring(0, line.indexOf(' ')));
		R = parseInt(line.substring(line.indexOf(' ') + 1));

		if (H > -R) {
			System.out.println(1);
		} else if (H == -R) {
			System.out.println(0);
		} else {
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 24296
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using vpii = vector<pii>;
using vs = vector<string>;
using vd = vector<double>;
using ul = unsigned long;
 
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; }
 
const int mod=1e9+7;
 
struct mint {
  ll x;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
};
 
mint c[4005][4005];
void init() {
  c[0][0] = 1;
  for (int i = 0; i <= 4000; i++) {
    for (int j = 0; j <= i; j++) {
      c[i+1][j] += c[i][j];
      c[i+1][j+1] += c[i][j];
    }
  }
}
mint comb(int n, int k) {
  return c[n][k];
}
 
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
 
    return true;
}
 
map<ll, ll> primeFact(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
 
void printv(vi& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
void printv(vll& v){
  rep(i,v.size()) cout << v[i] << " ";
  cout << endl;
}
int vtotal(vi& v){
  int total=0;
  rep(i,v.size()) total+=v[i];
  return total;
}
 
int main()
{
  //init(); // mint初期化
  cin.tie( 0 );
  ios::sync_with_stdio( false );
  
  int r,g,b;cin>>r>>g>>b;
  int total=r*100+g*10+b;
  string ans="NO";
  if(total%4==0)ans="YES";
  cout(ans);
  
  return 0;
}

Measured memory_bytes: 125568
import sys
while True:
    (H, W) = [int(i) for i in sys.stdin.readline().split()]
    if H == W == 0:
        break
    line = "#." * int(W / 2 + 1)
    for i in range(H):
        if i % 2:
            print(line[1:W+1])
        else:
            print(line[:W])
    print("")

Measured memory_bytes: 7680
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

class UnionFind {
public:
    vector <int> par;
    vector <int> siz;

    UnionFind(int sz_): par(sz_), siz(sz_, 1LL) {
        for (int i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(int sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (int i = 0; i < sz_; ++i) par[i] = i;
    }

    int root(int x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }

    bool unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    int size(int x) {
        return siz[root(x)];
    }
};

signed main() {
  int N, M, K; 
  cin >> N >> M >> K;

  UnionFind uf(N);

  vector<int> in(N, 0);
  REP(i, M){
    int u, v;
    cin >> u >> v;
    u--; v--;
    uf.unite(u, v);
    in[u]++;
    in[v]++;
  }

  vector<vector<int>> graph(N);
  REP(i, K){
    int u, v;
    cin >> u >> v;
    u--; v--;
    graph[u].emplace_back(v);
    graph[v].emplace_back(u);
  }
  
  vector<int> ans(N);
  REP(i, N){
    ans[i] = uf.size(i)-in[i]-1;
    for(auto p : graph[i]){
      if(uf.same(i, p)) ans[i]--;
    }
  }

  REP(i, N){
    cout << ans[i]; SPBR(i, N);
  }

  return 0;
}

Measured memory_bytes: 9856
#include<bits/stdc++.h>//头文件
using namespace std;
long long q,h,s,d,n;
int main(){
    cin>>q>>h>>s>>d>>n;
    cout<<(n%2==0?min(min(min(q*8,h*4),s*2),d)*n/2:min(min(q*4,h*2),s)+min(min(min(q*8,h*4),s*2),d)*(n-1)/2);
}

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

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

template<class T>
inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline T GCD(T a, T b) {
    return b ? GCD(b, a % b) : a;
}
template<class T>
inline T LCM(T a, T b) {
    return (a + (b - 1)) / b;
}

int round_int(int a, int b) {
    return (a + (b - 1)) / b;
}

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

constexpr array<int, 9> cost = { 2,5,5,4,5,6,3,7,6 };
const string MINUS_INF = "-";

string dp[11000];

void chmax(string& a, string b) {
    if (a == MINUS_INF) a = b;
    else if (a.size() < b.size()) a = b;
    else if (a.size() == b.size()) {
        if (a < b) a = b;
    }
}

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

    vi a(m);
    rep(i, m) cin >> a[i];

    rep(i, 11000) dp[i] = MINUS_INF;
    dp[0] = "";

    for(int i = 0; i <= n; ++i) {
        if (dp[i] == MINUS_INF) continue;
        rep(j, m) {
            chmax(dp[i + cost[a[j] - 1]], dp[i] + char('0' + a[j]));
        }
    }
    cout << dp[n] << endl;
}

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

def ans(x):
  a=26
  b=1
  k=1
  ch=0
  while ch==0:
    
    if b<= x <= b+a**k-1:
      ch+=1
      return k,x-(b-1)
    else:
      b=b+a**k
      k+=1

s,t=ans(n)
ans1=''
c='abcdefghijklmnopqrstuvwxyz'
for i in range(1,s+1):
  q=0
  f=26**(s-i)
  if i!=s:
    cc=0
    while cc==0:
      e=t-f*(q+1)
      if e>0:
        q+=1
      else:
        cc+=1
      if q==25:
        break
    t-=f*q
    g=c[q]
    ans1=ans1+g
    
  else:
    g=c[t-1]
    ans1=ans1+g
      
print(ans1)

Measured memory_bytes: 8988
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;

int n;
string s[100005];
vector<char> v;

map<pair<pii, pii>, int> dp;

int recur(int id, int a, int b, int c){
    if(a < 0 || b < 0 || c < 0) return -1;
    if(id >= n) return 1;
    if(dp[{{id, a}, {b, c}}]) return dp[{{id, a}, {b, c}}];

    int flag = -1;
    if(s[id] == "AB"){
        if(recur(id + 1, a + 1, b - 1, c) == 1){
            flag = 1;
            v.pb('A');
        }
        else if(recur(id + 1, a - 1, b + 1, c) == 1){
            flag = 1;
            v.pb('B');
        }
    }
    else if(s[id] == "BC"){
        if(recur(id + 1, a, b + 1, c - 1) == 1){
            flag = 1;
            v.pb('B');
        }
        else if(recur(id + 1, a, b - 1, c + 1) == 1){
            flag = 1;
            v.pb('C');
        }
    }
    else{
        if(recur(id + 1, a + 1, b, c - 1) == 1){
            flag = 1;
            v.pb('A');
        }
        else if(recur(id + 1, a - 1, b, c + 1) == 1){
            flag = 1;
            v.pb('C');
        }
    }

    return dp[{{id, a}, {b, c}}] = flag;
}
 
signed main()
{
    tezz

    int a, b, c;
    cin>>n>>a>>b>>c;

    for(int i=0;i<n;i++) cin>>s[i];

    if(recur(0, a, b, c) == 1){
        cout<<"Yes"<<endl;

        reverse(all(v));
        for(char c:v) cout<<c<<endl;
    }
    else cout<<"No";
} 

Measured memory_bytes: 24760
#include<stdio.h>
int main(void){
  int n,x=0,i,xmax=0;
  char s[101];
  scanf("%d",&n);
  scanf("%s",s);
  for(i=0;i<n;i++){
    if(s[i]=='I')x++;
    else if(s[i]=='D')x--;
    if(x>xmax)xmax=x;
  }
  printf("%d",xmax);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define ALL(a) a.begin(),a.end()
typedef long long ll;
#define INF 1<<30

int main()
{
    string S;
    int count = 0;
    cin >> S;
    int len = S.size();
    REP(i,len){
        count += (int)S[i]-48;
    }
    if(count%9==0)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int N;
vector<int> cnt, tmp;

int main() {
    cin>>N;
    cnt = vector<int>(26, 1e9);
    for(int i = 0; i < N; i++) {
        string s; cin>>s;
        tmp = vector<int>(26, 0);
        for(int j = 0; j < s.size(); j++) {
            tmp[ s[j] - 'a' ]++;
        }
        for(int j = 0; j < 26; j++) {
            cnt[j] = min(cnt[j], tmp[j]);
        }
    }
    for(int i = 0; i < 26; i++) {
        char t = 'a' + i;
        for(int j = 0; j < cnt[i]; j++) {
            cout << t;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (((a)%mod) * ((b)%mod)) % mod
#define rollcall cout << "I'm Sucu." << endl;
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pf(x) push_front(x)
#define fi first
#define se second
// debug
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << "(" << p.first << "," << p.second << ")";return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if(it != v.begin())os << " ";os << *it;
  }return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &mp){
  for(auto x: mp)os << "(" << x.first << "," << x.second << ")" << endl;
  return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void PRINTF(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void PRINTF(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}
string substr(const string &str, int S1, int S2 = -1){
  if(S2 == -1)return str.substr(S1);
  return str.substr(S1, S2-S1);
}
// typedef
typedef complex<double> Point;
typedef pair<int, int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;
// int sum = accumulate(a, a+n, 0LL);
// int mx = max_element(a, a+n);
// int mn = min_element(a, a+n);
// int cnt = count(a, a+n, k);


signed main(){
  string str;
  cin >> str;
  int n = str.size();
  int a = 0, b = 0;
  rep(i,n){
    if(str[i] == '1')a++;
    else b++;
  }
  cout << min(a, b) * 2 << endl;
  return 0;
}






Measured memory_bytes: 512
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
import math
N=i1()
x=[]
for i in range(N):
 z=i2()
 x.append([math.atan2(z[1],z[0]),z])

x.sort()
a=0
for i in range(N):
 s1=[0,0]
 aa=0
 for j in range(N):
   y1=(i+j)%N
   s1[0]+=x[y1][1][0]
   s1[1]+=x[y1][1][1]
   aa=max(aa,math.sqrt(s1[0]**2+s1[1]**2))
   
 a=max(a,aa)
 
print(a)

Measured memory_bytes: 39280
#ifdef Rahul
# include "RAHUL.h"
#else
# include <bits/stdc++.h>
  using namespace std;
# define error(...) 42;
#endif
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
const int MOD = (int) 1e9 + 7;
const i64 INF = (i64) 1e18 + 42;


int main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int a, b;
  cin >> a >> b;
  kek(a * b);
}


Measured memory_bytes: 3648
x,n=map(int,input().split())

import sys
if n==0:
    print(x)
    sys.exit()
p=list(map(int,input().split()))
if x not in p:
    print(x)
    sys.exit()
min=x
max=x

while True:
    min-=1
    max+=1
    if min not in p:
        ans=min
        break
    if max not in p:
        ans=max
        break
print(ans)

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

int main()
{
    int n,m,i,j,ni,nj,mi,mj;
    bool ans = false;
    char x;
    std::cin>>n>>m;
    std::cin.ignore();
    std::vector<std::vector<char>>ns(n,std::vector<char>(n));
    std::vector<std::vector<char>>ms(m,std::vector<char>(m));
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            std::cin>>x;
            ns[i][j] = x;
        }
        std::cin.ignore();
    }
    for(i=0;i<m;i++){
        for(j=0;j<m;j++){
            std::cin>>x;
            ms[i][j] = x;
        }
        std::cin.ignore();
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(i<=n-m && j<=n-m){
                int co=0;
                for(mi=0,ni=i;mi<m;mi++,ni++){
                    for(mj=0,nj=j;mj<m;mj++,nj++){
                        if(ns[ni][nj]==ms[mi][mj])co++;
                    }
                }
                if(co==m*m){
                    ans = true;
                }
            }
        }
    }
    (ans)?
    std::cout<<"Yes"<<std::endl:
    std::cout<<"No"<<std::endl;
}


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

using namespace std;

#define ll  long long
#define ld  double

#define sz(x)   (int)x.size()
#define all(x)  x.begin(),x.end()

#define pb  emplace_back
#define X   first
#define Y   second

const int   N   = 5005;

typedef pair<int,int>   ii;

vector<int> g[N];

int p[N];
int s[N];

ii  dfs(int u)  {
    int Sum = 0;

    vector<bool> F(s[u] + 1,0); F[0] = 1;
    vector<bool> G(s[u] + 1,0);

    for(int v : g[u])   {
        ii  C = dfs(v);
        Sum += C.X;
        Sum += C.Y;

        for(int i = C.X ; i <= s[u] ; ++i)  if (F[i - C.X]) G[i] = 1;
        for(int i = C.Y ; i <= s[u] ; ++i)  if (F[i - C.Y]) G[i] = 1;

        F.swap(G);
        G.assign(s[u] + 1,0);
    }
    while (F.size() && F.back() == 0)
        F.pop_back();
    
    if (F.empty())  {
        cout << "IMPOSSIBLE";
        exit(0);
    }
    return  ii(s[u],Sum - F.size() + 1);
}

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

    int n;  cin >> n;

    for(int i = 2 ; i <= n ; ++i)   cin >> p[i];
    for(int i = 1 ; i <= n ; ++i)   cin >> s[i];

    for(int i = 2 ; i <= n ; ++i)
        g[p[i]].pb(i);
    
    dfs(1); cout << "POSSIBLE";
}

Measured memory_bytes: 4144
#include<iostream>
using namespace std;
bool de4(int x){
    if (x%3==0){
      return true;
    }
  while (x>0){
    if(x%10 == 3)return true;
    x = x/10;
  }
  return false;
}
int main(){
  int n;
  cin>>n;
  int i;
  
  for(i=1;i<=n;i++)
    {
      if(de4(i) == 1){
	cout << " " << i;
      }
    }
      cout<<endl;
    
}



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

int main(){
   int t, n;
  while(cin >> n){
   t = 0;
   for(int a = 0;a < 10;a++){
     for(int b = 0;b < 10;b++){
       for(int c = 0;c <10;c++){
         for(int d = 0;d < 10;d++){
            if(a + b + c + d == n)
            ++t;       
         }
       }
     }
   }
   cout << t << endl;
 }
 return 0;
 }

Measured memory_bytes: 1160
/*author: hyperion_1724
  date: 
*/

#pragma GCC optimize("Os")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")

//Required Libraries

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

//Required namespaces

using namespace std;
using namespace __gnu_pbds;

//Required defines

#define READ(X) cin>>X;
#define READV(X) long long X; cin>>X;
#define READAR(A,N) long long A[N]; for(int i=0;i<N;i++) {cin>>A[i];}
#define rz(A,N) A.resize(N);
#define sz(X) (long long)(X.size())
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define endl '\n'
#define trav(x,A) for(auto &x:A)
#define veci vector<int>
#define vecl vector<long long>
#define FORI(a,b,c) for(int a=b;a<c;a++)
#define FORD(a,b,c) for(int a=b;a>c;a--)

//Required typedefs

typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> ordered_set1;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

//Required Constants

const long long inf=(long long)1e18;
const long long MOD=(long long)(1e9+7);
const long long INIT=(long long)(1e6+1);

//Required Functions

ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % MOD; 
    p = (p * p) % MOD; 
  
    return (y%2 == 0)? p : (x * p) % MOD; 
}
ll modInverse(ll a) 
{ 
   return power(a,MOD-2); 
   
}

//Work
ll N;
ll A[1000];
ll dp[1000][1000];
ll pref[1000];
inline void sumwork()
{
	FORI(i,1,N+1)
	{
		pref[i]=pref[i-1]+A[i];
	}
	FORI(i,N+1,2*N+1)
	{
		pref[i]=pref[i-1]+A[i-N];
	}
}
inline ll sum(ll s,ll e)
{
	if (s<=e)
	{
		return pref[e]-pref[s-1];
	}
	else
	{
		return pref[N+e]-pref[s-1];
	}
}
inline ll make(ll s,ll e)
{
	if (s==e)
	{
		dp[s][e]=0;
		return 0;
	}
	else if(dp[s][e]!=-1)
	{
		return dp[s][e];
	}
	else
	{
		dp[s][e]=inf;
		ll x=s;
		while(x!=e)
		{
			if (x+1>=N)
			{
				dp[s][e]=min(dp[s][e],make(s,x)+make((x+1)-N,e)+sum(s+1,e+1));
			}
			else
			{
				dp[s][e]=min(dp[s][e],make(s,x)+make(x+1,e)+sum(s+1,e+1));
			}
			x++;
			if (x>=N)
			{
				x=x-N;
			}
		}
		return dp[s][e];
	}
}

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

    ll T=1;
	while(T--)
	{
		READ(N);
		FORI(i,0,N+2)
		{
			FORI(j,0,N+2)
			{
				dp[i][j]=-1;
			}
		}
		FORI(i,0,2*N+5)
		{
			pref[i]=0;
			A[i]=0;
		}
		FORI(i,1,N+1)
		{
			cin>>A[i];
		}
		sumwork();
		ll ans=make(0,N-1);
		cout<<ans<<endl;
	}	

	return 0;
}

Measured memory_bytes: 4224
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))

for i in range(n):
    p[i] -= 1

ans = -12345678901234567
for st in range(n):
    score = 0
    now = st

    # ループするまで or kまで
    for i in range(1,k+1):
        now = p[now]
        score += c[now]
        ans = max(ans,score)
        if now == st:
            cnt = k//i - 1
            if cnt > 1:
                score *= cnt
                i *= cnt
                ans = max(ans,score)
            break

    for j in range(i+1,k+1):
        now = p[now]
        score += c[now]
        ans = max(ans,score)
print(ans)

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

int main(void) {
    string w;
    cin >> w;
    int n;
    for(char c = 'a'; c <= 'z'; ++c) {
        n = 0;
        for(int i = 0; i < (int)w.length(); ++i) {
            if(w[i] == c) ++n;
        }
        if(n % 2 == 1) {cout << "No" << endl; return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = (1LL<<60);
constexpr ll MOD = (1e9+7);
//constexpr ll MOD = (998244353);
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(a>b){a=b;return 1;}return 0;}
#if loc||local
void dump(){cerr<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int h,w;
  cin>>h>>w;
  vector<string> s(h);
  cin>>s;

  using T = tuple<int,int,int,int>;
  // y,x,state('.','#),cost
  queue<T> que;
  if(s[0][0]=='.')que.emplace(0,0,0,0);
  else que.emplace(0,0,1,1);
  const int dx[] = {0,1};
  const int dy[] = {1,0};
  vector<vector<ll>> dist(h,vector<ll>(w,INF));
  while(!que.empty()){
    ll y,x,state,cost;
    tie(y,x,state,cost) = que.front();
    que.pop();
    if(chmin(dist[y][x],cost)){
      for(int i=0;i<2;++i){
        int ny=y+dy[i];
        int nx=x+dx[i];
        if(ny==h||nx==w||ny==-1||nx==-1)continue;
        int nxt_state = (s[ny][nx]=='#');
        int nxt_cost;
        if(state==0&&nxt_state==1)nxt_cost = cost+1;
        else nxt_cost = cost;
        que.emplace(ny,nx,nxt_state,nxt_cost);
      }
    }
  }
  cout<<(dist[h-1][w-1])<<endl;


}

Measured memory_bytes: 384
n=int(input())
ans=0
time_now=0
x_now=0
y_now=0
for i in range(n):
  time,x,y=map(int,input().split())
  jikan=time-time_now
  kyori=abs(x-x_now)+abs(y-y_now)
  if(jikan>=kyori and jikan%2==kyori%2):
    ans+=0
  else:
    ans+=1
  time_now=time
  x_now=x
  y_now=y
  
if(ans==0):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <string.h>
#include <stdio.h>

typedef struct _DICE DICE;
struct _DICE{
    int a[6];
    char b[101];
};


int main(int argc, const char * argv[]) {
    DICE Dice;
    int q;
    int i;//アクセス用変数
    int a,b,c=0;
    int ans[100];
    
    
    for(i=0;i<6;i++){
        scanf("%d",&Dice.a[i]);
    }
    scanf("%d",&q);
    
    for(i=0;i<q;i++){
        scanf("%d %d",&a,&b);
        
        if(a==Dice.a[0]){
            if(b==Dice.a[1]){
                c=Dice.a[2];
            }else if(b==Dice.a[2]){
                c=Dice.a[4];
            }else if(b==Dice.a[3]){
                c=Dice.a[1];
            }else if(b==Dice.a[4]){
                c=Dice.a[3];
            }
        }else if(a==Dice.a[1]){
            if(b==Dice.a[0]){
                c=Dice.a[3];
            }else if(b==Dice.a[2]){
                c=Dice.a[0];
            }else if(b==Dice.a[3]){
                c=Dice.a[5];
            }else if(b==Dice.a[5]){
                c=Dice.a[2];
            }
        }else if(a==Dice.a[2]){
            if(b==Dice.a[0]){
                c=Dice.a[1];
            }else if(b==Dice.a[1]){
                c=Dice.a[5];
            }else if(b==Dice.a[4]){
                c=Dice.a[0];
            }else if(b==Dice.a[5]){
                c=Dice.a[4];
            }
        }else if(a==Dice.a[3]){
            if(b==Dice.a[0]){
                c=Dice.a[4];
            }else if(b==Dice.a[1]){
                c=Dice.a[0];
            }else if(b==Dice.a[4]){
                c=Dice.a[5];
            }else if(b==Dice.a[5]){
                c=Dice.a[1];
            }
        }else if(a==Dice.a[4]){
            if(b==Dice.a[0]){
                c=Dice.a[2];
            }else if(b==Dice.a[2]){
                c=Dice.a[5];
            }else if(b==Dice.a[3]){
                c=Dice.a[0];
            }else if(b==Dice.a[5]){
                c=Dice.a[3];
            }
        }else if(a==Dice.a[5]){
            if(b==Dice.a[1]){
                c=Dice.a[3];
            }else if(b==Dice.a[2]){
                c=Dice.a[1];
            }else if(b==Dice.a[3]){
                c=Dice.a[4];
            }else if(b==Dice.a[4]){
                c=Dice.a[2];
            }
            
        }
        
        ans[i]=c;//答えを入れる
    }
    
    for(i=0;i<q;i++){
        printf("%d\n",ans[i]);
    }
    
    return 0;
}


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

using namespace std;

int main()
{
    int vis[150];
    memset(vis , 0 , sizeof vis);
    int x, y , n;
    cin >> x >> y;
    for(int i = 0 ; i <y ;i++)
    {
        cin >> n ;
        vis[n]=1;
    }
    int tmp=x;
    while(vis[tmp]!=0)
    {
        tmp--;
    }
    int ans=tmp;
    tmp=x;
    while(vis[tmp]!=0)
    {
        tmp++;
    }
    if(tmp-x < x-ans)
    {
        ans=tmp;
    }
    cout << ans;
    return 0;
}


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

namespace ABC067_B
{
    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string[] str = input.Split(' ');
            int sticks = int.Parse(str[0]);
            int selectStickAmount = int.Parse(str[1]);

            var stickLengthList = new List<int>();
            string inputLength = Console.ReadLine();
            string[] inputArray = inputLength.Split(' ');
            for (int i = 0; i < sticks; i++)
            {
                stickLengthList.Add(int.Parse(inputArray[i]));
            }
            stickLengthList.Sort();
            stickLengthList.Reverse();

            int sumLength = 0;
            for (int i = 0; i < selectStickAmount; i++)
            {
                sumLength += stickLengthList[i];
            }
            Console.WriteLine(sumLength);
        }
    }
}


Measured memory_bytes: 11604