akhauriyash/Code-Regression huggingface dataset:
S = input()
check = set("AGCT")

max_cnt = 0
for i in range(len(S)):
  cnt = 0
  for j in range(0,len(S)-i):
    #print(S[i+j],end="")
    if S[i+j] in check:
      cnt += 1
      max_cnt = max(max_cnt,cnt)
    else:
      break
      
print(max_cnt)


Measured memory_bytes: 9032
n, k = map(int, input().split())
ans = [0] * n
cnt = 0
for i in range(k):
    d = int(input())
    a = list(map(int, input().split()))
    for j in a:
        ans[j-1] += 1
for i in ans:
    if i == 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 9192
#include<stdio.h>

#define N 100000
#define NIL -1

struct Node{
  int p;
  int l;
  int r;
};
 
struct Node T[N];
int De[N];
 
int Depth(int x){
  int sum = 0;
  while(T[x].p != NIL){
    sum++;
    x = T[x].p;
  }
  return sum;
}
 
 
int sibling(int x){
  if(T[x].p == NIL) return NIL;
  if(T[T[x].p].r == x) return T[T[x].p].l;
  if(T[T[x].p].l == x) return T[T[x].p].r;
}
 
int degree(int x){
  int sum = 0;
  if(T[x].l != NIL) sum++;
  if(T[x].r != NIL) sum++;
  return sum;
}
 
int height(int x){
  int height1 = 0;
  int height2 = 0;
 
  if(T[x].l != NIL) height1 = height(T[x].l) + 1;
  if(T[x].r != NIL) height2 = height(T[x].r) + 1;
 
  if(height1 < height2) return height2;
  else return height1;
}
 
 
main(){
  int v,d,c,s;
  int n;
  int i,j,m;
 
 
 
  scanf("%d",&n);
 
  for(i=0; i < n; i++){
    T[i].p = T[i].l = T[i].r = NIL;
  }
   

  for(j = 0; j < n; j++){
    scanf("%d",&v);
    scanf("%d %d",&T[v].l,&T[v].r);
 
    T[T[v].l].p = v;
    T[T[v].r].p = v;
  }
 

  for(i = 0; i < n; i++){
    De[i] = Depth(i);
  }
 

  for(m = 0; m<n; m++){
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, "
                                                        ,m,T[m].p, sibling(m), degree(m),De[m],height(m));
 
    if(T[m].p == NIL) printf("root\n");
    else if(T[m].l != NIL || T[m].r != NIL)printf("internal node\n");
    else printf("leaf\n");
  }
  return 0;
}

Measured memory_bytes: 616
def main():
    h,w,a,b=map(int,input().split(' '))
    mod = 10**9+7
    mx=max(h,w)
    fac=[1]*(h+w+1)
    for i in range(1,h+w+1):
        fac[i]=fac[i-1]*i%mod
    rev=[1]*(mx+1)
    rev[-1]=pow(fac[mx],mod-2,mod)
    for i in range(mx-1,-1,-1):
        rev[i]=rev[i+1]*(i+1)%mod
    const=rev[h-a-1]*rev[a-1]%mod
    ans = sum(fac[h - a + i - 1] * rev[i] * fac[a + w - 2 - i] * rev[w - i - 1] % mod for i in range(b, w))
    print(ans * const % mod)



if __name__ == '__main__':
    main()


Measured memory_bytes: 14836
import java.io.*;
import java.util.*;

public class Main {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	void solve() throws IOException {
		int n = nextInt();
		
		int[] pos = new int[n];
		
		for (int i = 1; i <= n; i++) {
			pos[nextInt() - 1] = i;
		}
		
		int[] left = new int[n + 2];
		int[] right = new int[n + 2];
		Arrays.fill(left, -1);
		Arrays.fill(right, -1);
		
		long ans = 0;
		
		for (int i = n - 1; i >= 0; i--) {
			int x = pos[i];
			int newLeft = (left[x - 1] == -1 ? x : left[x - 1]);
			int newRight = (right[x + 1] == -1 ? x : right[x + 1]);
			
//			System.err.println(newLeft + " " + newRight);
			
			
			
			ans += (long)(i + 1) * (newRight - x + 1) * (x - newLeft + 1);
			left[newRight] = newLeft;
			right[newLeft] = newRight;
		}
		
		out.println(ans);
	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				eof = true;
				return null;
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
}

Measured memory_bytes: 31792
//------------------------------------------------------------------------------MANAS UNIYAL---------------------------------------------------------
//                                                                              NEVER GIVE UP
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);	cin.tie(NULL);	cout.tie(NULL);
#define ll long long
#define pb push_back
#define fi first 
#define se second
#define pii pair<ll,ll>
#define INF 0x3f3f3f3f
#define LINF 98765432123456789
#define testcases() ll t; cin>>t; while(t--)
#define debug1(x) cout<<#x<<" "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define debug4(w,x,y,z) cout<<#w<<" "<<w<<" "<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<"\n";
#define rep(i,start,end) for(ll i=start;i<end;i++)
 
//----------------------------------------------------------------------------------------------------------------------------------------------------

int main()
{
	fast;
	ll n;
    cin>>n;
	ll sum = 0;
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=n;j++)
		{
			for(ll k=1;k<=n;k++)
			{
				ll gcd = __gcd(i,j);
				gcd = __gcd(gcd,k);
				//debug1(gcd)
				sum += gcd;
			}
		}
	}
	cout<<sum;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
int H,A[5000001]={};

void mh(int i){
  int l=i*2,r=i*2+1,lar=i;
  if(A[l]>A[i]&&l<=H)lar=l;
  if(A[r]>A[lar]&&r<=H)lar=r;
    
  if(lar!=i){
    swap(A[lar],A[i]);
    mh(lar);
  }
}

int main(){
  cin>>H;
  for(int i=1;i<=H;i++)cin>>A[i];
  for(int i=H/2;i>0;i--)mh(i);
  for(int i=1;i<=H;i++)cout<<" "<<A[i];
  cout<<endl;
  return 0;
}

Measured memory_bytes: 5024
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>

using namespace std;

int main()
{
    string s;
    cin >> s;
    bool flag = false;
    if (s[0] != 'A') {
        cout << "WA\n";
        return 0;
    }
    if (s[1] < 97 or s[1] > 122) {
        cout << "WA\n";
        return 0;
    }
    else {
        for (int i=2; i<s.length()-1; i++) {
            if (s[i] == 'C') flag = true;
        }
        if (!flag) {
            cout << "WA\n";
            return 0;
        }
        int cnt = 0;
        for (int i=2; i<s.length()-1; i++) {
            if (s[i] < 97 or s[i] > 122) {
                if (s[i] == 'C') cnt++;
                else {
                    cout << "WA\n";
                    return 0;
                }
            }
            if (cnt > 1) {
                cout << "WA\n";
                return 0;
            }
        }
        if (s[s.length()-1] < 97 or s[s.length()-1] > 122) {
            cout << "WA\n";
            return 0;
        }
    }
    cout << "AC\n";
    
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define vi vector<int> 
#define vll vector<ll> 
#define vpll vector<pair<ll ,ll>>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define map map<ll ,ll>
#define umap unordered_map<ll , ll>
#define endl "\n"
#define set set<ll> 
#define setC set<char>
#define fast ios::sync_with_stdio(0); cin.tie(0);
#define fastcout ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define testcases int tt = 1 ; cin >> tt ; for(int i = 1 ; i <= tt ; ++i)
#define codejam cout << "Case #"<<i <<": "; 
#define FOR(i,a,n) for(int i = a ; i <= n ; ++i)
#define FORback(i,a,n) for(int i = n ; i >= a ; --i)
#define ll long long int 
const ll INF = 1e13 + 7 ;
 
void solv(){
    ll n,w;
    cin>>n>>w;
    vpll v(n);
    ll sum=0;
 
    for(ll i=0;i<n;i++){
        cin>>v[i].first>>v[i].second;
        sum+=v[i].second;
    }
 
    vector<vector<ll> > dp(n+1,vector<ll>(sum+1,INF));
 
    for(ll i=0;i<=n;i++){
        dp[i][0]=0;
    }
 
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=sum;j++){
            dp[i][j]=dp[i-1][j];
            if(j >= v[i-1].second)
                dp[i][j]=min(dp[i][j],v[i-1].first+dp[i-1][j-v[i-1].second]);
        }
    }
    ll ans=0;
 
    /*for(ll i=0;i<=n;i++){
        for(ll j=0;j<=sum;j++){
            cout<<dp[i][j]<<" ";
        }
        cout<<endl;
    }*/
 
    for(ll i=0;i<=sum;i++){
        if(dp[n][i]<=w){
            ans=max(ans,i);
        }
    }
 
    cout<<ans << endl;
}
 
int main(){
    fast ;    
    // testcases{
        // codejam ;
        solv();
    // } 
}
 

Measured memory_bytes: 83000
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int a, b;
    cin >> a >> b;

    if (b%a == 0) 
        cout << a+b << endl;
    else
        cout << b-a << endl;
    
    return 0;
}

Measured memory_bytes: 256
N = int(input())
es = [[] for i in range(N)]
cand = set()
for i in range(N):
  es[i] = [int(i)-1 for i in input().split()][::-1]
def check(i):
  if es[i]==[]:
    return
  j = es[i][-1]
  if es[j]==[]:
    return
  if es[j][-1]==i:
    cand.add(i)
    cand.add(j)

for i in range(N):
  check(i)
day = 0
while cand:
  day += 1
  precand = cand.copy()
  cand = set()
  for i in precand:
    x = es[i].pop()
  for i in precand:
    check(i)
for i in range(N):
  if len(es[i])!=0:
    print(-1)
    break
else:
  print(day)


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

int main() {
    int a, b; cin >> a >> b;
    if (a <= b) cout << a << endl;
    else cout << a-1 << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,p,q;
    cin>>a>>b;
    if(a>b)
    {
        p=a;
        q=b;
    }
    else
   { p=b;
     q=a;
   }
    for(int i=0;i<p;i++)
    cout<<q;
}

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

double x[10],y[10];

double get_dis(int i, int j)
{
	return sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
}

int main()
{
	
	std::ios::sync_with_stdio(false);cin.tie(0);
	int n; cin >> n;
	for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
	int a[11];
	for(int i = 1; i <= n; i++) a[i] = i;
	double ans = 0;
	while(next_permutation(a + 1,a + n + 1)){
		for(int i = 1; i < n; i++) {
			ans += get_dis(a[i],a[i + 1]);
		}
		//cout << ans << endl;
	}
	for(int i = 1; i < n; i++) {
		ans += get_dis(i,i + 1);
	}
	for(int i = 1; i <= n; i++) {
		ans /= i;
	}
	printf("%.6f",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    string s;
    cin>>s;
    int a,b;
    a=(s[0]-'0')*10+s[1]-'0';
    b=(s[2]-'0')*10+s[3]-'0';
    if(a>=1&&a<=12&&b>=1&&b<=12)
    {
        cout<<"AMBIGUOUS"<<endl;
        return 0;
    }
    if(a>=1&&a<=12)
    {
        cout<<"MMYY"<<endl;
        return 0;
    }
    if(b>=1&&b<=12)
    {
        cout<<"YYMM"<<endl;
        return 0;
    }
    cout<<"NA"<<endl;
    return 0;
}


Measured memory_bytes: 256
N = int(input())

def rangesqrt(n):
    i = 1
    while i * i <= n:
        yield i
        i += 1

pos = ((d, N // d) for d in rangesqrt(N) if N % d == 0)
print(min(x - 1 + y - 1 for x, y in pos))


Measured memory_bytes: 2940
H, W = [int(i) for i in input().split()]

if H>1 and W>1:
    print(((H + 1) // 2) * ((W + 1) // 2) +
        (H - (H + 1) // 2) * (W - (W + 1) // 2))
else:
    print(1)


Measured memory_bytes: 38256
h, w = map(int, input().split())
s_list = [list(input()) for _ in range(h)]
dx_list = [1, 1, 0, -1, -1, -1, 0, 1]
dy_list = [0, 1, 1, 1, 0, -1, -1, -1]
for i in range(h):
    for j in range(w):
        if s_list[i][j] == '#':
            continue
        num = 0
        for dx, dy in zip(dx_list, dy_list):
            x = j + dx
            y = i + dy
            if x < 0 or x >= w:
                continue
            if y < 0 or y >= h:
                continue
            if s_list[y][x] == '#':
                num += 1
        s_list[i][j] = str(num)
    answer = ''.join(s_list[i])
    print(answer)

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] array = new int[3]; 
		array[0] = sc.nextInt();
		array[1] = sc.nextInt();
		array[2] = sc.nextInt();
		Arrays.sort(array);
		System.out.println(array[0] + " " + array[1] + " " + array[2]);
	}
}

Measured memory_bytes: 17348
#include <iostream>

using namespace std;

int main()
{
    int A, B;
    cin >> A >> B;

    int sockets = 1;
    int count = 0;
    while(sockets < B)
    {
        sockets += A - 1;
        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>

typedef long long ll;
using namespace std;
const ll x=1000000007;
int mod(ll a){
	return a%x;
}
int main(){
	string s;
	cin>>s;
	ll a=0,b=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='1'){
			a++;
		}
		if(s[i]=='0'){
			b++;
		}
	}
	cout<<2*(min(a,b));	
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            if (N[N.Length - 1] == '2' || N[N.Length - 1] == '4' || N[N.Length - 1] == '5' || N[N.Length - 1] == '7' || N[N.Length - 1] == '9')
            {
                Console.WriteLine("hon");
            }
            else if (N[N.Length - 1] == '0' || N[N.Length - 1] == '1' || N[N.Length - 1] == '6' || N[N.Length - 1] == '8')
            {
                Console.WriteLine("pon");
            }
            else
            {
                Console.WriteLine("bon");
            }
        }
    }
}


Measured memory_bytes: 17352
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

vector<vector<int>> grp;

void go(int n,deque<int> &dq,bool b,set<int> &vis){
	if(b) dq.emplace_back (n+1);
	else  dq.emplace_front(n+1);
	for(auto &i:grp[n]){
		if(!vis.count(i)){
			vis.insert(i);
			go(i,dq,b,vis);
			return;
		}
	}
	return;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,e; cin>>n>>e;
	grp.resize(n);
	int s,t;
	For(i,0,e-1){
		cin>>s>>t;
		s--; t--;
		grp[s].emplace_back(t);
		grp[t].emplace_back(s);
	}
	deque<int> dq;
	set<int> vis;
	vis.insert(0);
	go(0,dq,1,vis);
	dq.pop_front();
	go(0,dq,0,vis);
	cout<<sz(dq)<<"\n";
	For(i,0,sz(dq)-1){
		cout<<dq[i]<<" \n"[i==sz(dq)-1];
	}
	return 0;
}





























Measured memory_bytes: 11776
//xenowi`tz -- Jai Shree Ram
#include<bits/stdc++.h>
using namespace std;

#define fori(i,a,b) for (long long int i = a; i <= b ; ++i)
#define ford(i,a,b) for(long long int i = a;i >= b ; --i)
#define mk make_pair
#define mod 1000000007
#define MAXN 400005
#define pb push_back
#define vec vector<long long int>
#define ll long long
#define rnd mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count())
#define pi pair<long long int,long long int>
#define sc second
#define fs first

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string s;
	cin >> s;

	if (s[2] == s[3] && (s[4] == s[5])) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}	

	return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

ll ans;
int plan[128];
int memo[128][4][4];
int num;

// n : day, next : kind of pasta, c : 今日選んだパスタが何日続いたか 
int pasta(int n, int prev, int c)
{
	if(c == 2)
	{
		return 0;
	}
	else if(n == num)
	{
		return 1;
	}
	else if(memo[n][prev][c])
	{
		return memo[n][prev][c];
	}
	int ans = 0;
	if(plan[n+1] != 0)
	{
		if(plan[n+1] == prev)
			ans = pasta(n+1, plan[n+1], c+1); 
		else
			ans =  pasta(n+1, plan[n+1], 0);
	}
	else
	{
		for(int i = 1; i <= 3; i++)
		{
			if(prev == i)
				ans +=  pasta(n+1, i, c+1);
			else
				ans +=  pasta(n+1, i, 0) ;
		}
	}

	return memo[n][prev][c] = ans % 10000;
}

int main()
{
	int K, wk, tk;
	ans = 0;
	cin >> num >> K;
	for(int i = 0; i < K; i++)
	{
		cin >> wk >> tk;
		plan[wk] = tk;
	}
	if(plan[1] == 0)
	{
		cout << pasta(0, 0, 0)<< endl;
	}
	else
	{
		cout << pasta(1, plan[1], 0)<<endl;
	}

}

Measured memory_bytes: 1172
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
/*迷路移動*/const int dx[4]={1,0,-1,0};const int dy[4]={0,1,0,-1};
llfor;//ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;
 cin>>n;
 ll a[n+10];
 map<ll,ll>used;
 used[0]=1;
 ll sum=0,ans=0;
 rep(i,0,n){
  cin>>a[i];
  sum+=a[i];
  if(used[sum]>0)ans+=used[sum];
  used[sum]++;
 // cout<<i<<" "<<sum<<endl;
 }
 pr(ans);
 return 0;}

Measured memory_bytes: 17632
import java.io.*;
import java.util.*;


public class Main {
    static long mod = 1000000000+7;
    static int maxn=2;
    static long[] f5ac, inv;
    static ArrayList<Integer>[] rec;
    static int[] p;
    static int n,m;
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        //BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        //String[] buf = reader.readLine().split(" ");
        n = sc.nextInt();m = sc.nextInt();
        rec = new ArrayList[m];
        for(int i=0;i<m;i++){
            rec[i] = new ArrayList<>();
            int k = sc.nextInt();
            for(int j=0;j<k;j++) rec[i].add(sc.nextInt()-1);
        }
        p = new int[m];
        int ans = 0;
        for(int i=0;i<m;i++) p[i]=sc.nextInt();
        for(int s=(1<<n)-1;s>=0;s--){
            if(check(s)) ans ++;
        }
        System.out.println(ans);
    }
    static boolean check(int state){
        for(int i=0;i<m;i++){
            // for every bulb
            int cur=0;
            for(int w:rec[i]){
                if((state&(1<<w))>0) cur ++;
            }
            if((cur%2)!=(p[i]%2)) return false;
        }
        return true;
    }
}



Measured memory_bytes: 23252
#include<stdio.h>
#define MAX 100005
#define NIL -1

struct Node { int p, l, r; };

struct Node T[MAX];
int n, D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

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

  printf("[");

  for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if (i) printf(", ");
    printf("%d", c);
  }

  printf("]\n");
}

//深さを求める
void rec(int u, int p){
  D[u] = p;
  if (T[u].r != NIL) rec(T[u].r, p);
  if (T[u].l != NIL) rec(T[u].l, p+1);
}

int main() {
  int i, j, d, v, c, l, r;
  scanf("%d", &n);

  //初期化
  for (i = 0; i < n; i++){
    T[i].p = T[i].l = T[i].r = NIL;
  }

  for (i = 0; i < n; i++){
    scanf(" %d %d", &v, &d);

    for (j = 0; j < d; j++){
      scanf(" %d", &c);

      if (j == 0) {
        T[v].l = c;
      } else {
        T[l].r = c;
      }
      l = c;
      T[c].p = v;
    }
  }

  for (i = 0; i < n; i++){
    if (T[i].p == NIL){
      r = i;
    }
  }

  rec(r, 0);

  for (i = 0; i < n; i++) print(i);

  return 0;
}


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

int sim(int i, int N, string& S, vector<int>& dest, vector<vector<char>>& td_list) {
  int idx = i;
  if (dest.at(i) != -2) return dest.at(i);
  for (vector<char> td : td_list) {
    if (idx == -1) {
      dest.at(i) = -1;
      return -1;
    }
    if (idx == N) {
      dest.at(i) = N;
      return N;
    }
    if (td.at(0) == S.at(idx)) {
      if (td.at(1) == 'L') {
        idx--;
      } else {
        idx++;
      }
    }
  }
  dest.at(i) = idx;
  return idx;
}

int main(void){
  int N, Q;
  cin >> N >> Q;
  string S;
  cin >> S;
  vector<int> dest(N, -2);
  vector<vector<char>> td_list(Q, vector<char>(2));
  for (int i = 0; i < Q; i++) {
    cin >> td_list.at(i).at(0) >> td_list.at(i).at(1);
  }
  
  // 左側の境界を探索
  int left = -1;
  int right = N;
  while (right - left != 1) {
    int mid = (left + right) / 2;
    if (sim(mid, N, S, dest, td_list) == -1){
      left = mid;
    } else {
      right = mid;
    }
  }
  int lb = right;

  // 右側の境界を探索
  left = -1;
  right = N;
  while (right - left != 1) {
    int mid = (left + right) / 2;
    if (sim(mid, N, S, dest, td_list) == N){
      right = mid;
    } else {
      left = mid;
    }
  }
  int rb = left;

  cout << rb - lb + 1 << endl;
}


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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

int main(void){
	int32 N;
	cin >> N;
	vector<int64> x(N), y(N), h(N);
	REP(i, N){
		cin >> x[i] >> y[i] >> h[i];
		int64 X = x[i]+y[i], Y = x[i]-y[i];
		x[i] = X; y[i] = Y;
	}
	REP(i, 101){
		REP(j, 101){
			int64 xx = i+j, yy = i-j;
			int64 H = -1;
			REP(k, N){
				if(h[k] > 0){
					H = h[k]+max(abs(xx-x[k]), abs(yy-y[k]));
					break;
				}
			}
			bool ok = 1;
			REP(k, N){
				if(h[k] != max((int64)0, H-max(abs(xx-x[k]), abs(yy-y[k])))){
					ok = 0;
				}
			}
			if(ok){
				cout << i << " " << j << " " << H << endl;
				return 0;
			}
		}
	}
}


Measured memory_bytes: 256
mod=10**9+7
s=input()
n=len(s)
dp=[13*[0]for _ in range(n)]
if s[0]=="?":dp[0]=[1]*10+[0]*3
else:dp[0][int(s[0])]=1
for i in range(1,n):
  for j in range(13):
    if s[i]=="?":
      for k in range(10):
        dp[i][(10*j+k)%13]+=dp[i-1][j]
        dp[i][(10*j+k)%13]%=mod
    else:
      dp[i][(10*j+int(s[i]))%13]+=dp[i-1][j]
      dp[i][(10*j+int(s[i]))%13]%=mod
print(dp[-1][5])


Measured memory_bytes: 61916
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  for(int i = 0; i < S.length(); i++){
 	if(i % 2 == 0){
    	if(S.at(i) == 'R' || S.at(i) == 'U' || S.at(i) == 'D'){
        	
        }else{
        	cout << "No" << endl;
          	break;
        }
    }else{
    	if(S.at(i) == 'L' || S.at(i) == 'U' || S.at(i) == 'D'){
        	
        }else{
        	cout << "No" << endl;
          	break;
        }
    }
    if(i == S.length()-1){
    	cout << "Yes" << endl;
    }
 }
}

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

int main() {
	long n, m, l, i, j, k,
		box1[100][100] = {},
		box2[100][100] = {},
		box3[100][100] = {};

	cin >> n >> m>>l;
	
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) {
			cin >> box1[i][j];
		}
	}
	for (i = 0; i < m; i++) {
		for (j = 0; j < l; j++) {
			cin >> box2[i][j];
		}
	}

	for (i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			for (k = 0; k < m; k++) {
				box3[i][j] += box1[i][k] * box2[k][j];
			}
		}
		}
	
	for(i = 0; i < n; i++) {
		for (j = 0; j < l; j++) {
			if (j == (l - 1)) {
				cout << box3[i][j];
			}
			else {
				cout << box3[i][j] << " ";
			}
		}
		cout << "\n";
	}
	return 0;
}


Measured memory_bytes: 3324
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#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 INF 10000000000;
using namespace std;
typedef unsigned long ul;
typedef long long ll;
typedef pair<ll, ll> p;

int main(void) {
    ll n;
    string s;
    cin >> n;
    cin >> s;
    ll ans=0, tmp;
    
    ll i, j;
    string tl, tr;
    for(i=1; i<s.size()-1; i++) {
        tmp=0;
        ll lcnt[26]={0}, rcnt[26]={0};
        tl=s.substr(0, i);
        tr=s.substr(i);
        
        for(j=0; j<tl.size(); j++)
            lcnt[tl[j]-'a']=1;
        for(j=0; j<tr.size(); j++)
            rcnt[tr[j]-'a']=1;
        
        for(j=0; j<26; j++) {
            if(lcnt[j]*rcnt[j]) tmp++;
        }
        ans=max(ans, tmp);
    }
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
def main():
    N, S = map(int, input().split())
    A = list(map(int, input().split()))
    MOD = 998244353
    dp = [[0] * (S+5) for _ in range(N+5)]
    dp[0][0] = 1
    for i in range(N):
        for j in range(S+1):
            dp[i+1][j] += 2 * dp[i][j]
            dp[i+1][j] %= MOD
            if j + A[i] <= S:
                dp[i+1][j+A[i]] += dp[i][j]
                dp[i+1][j+A[i]] %= MOD
    print(dp[N][S])



if __name__ == "__main__":
    main()

Measured memory_bytes: 132584
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223372036854775807
#define INF 2147483647
#define MOD 1000000007
using namespace std;

ll func(long n) {
    ll ans=1;
    long i;
    for(i=1; i<=n; i++) {
        ans = ans * i %MOD;
    }
    return ans;
}

int main(int argc, char* argv[])
{
    long n,m;
    scanf("%ld%ld", &n, &m);

    if(n==m) {
        printf("%lld\n", func(n) * func(n) * 2 % MOD);
    }
    else if (n==m+1) {
        printf("%lld\n", func(n) * func(m) % MOD);
    }
    else if (m==n+1) {
        printf("%lld\n", func(n) * func(m) % MOD);
    }
    else {
        printf("0\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#include<tuple>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

const ll mod = 1e9+7;
const ll INF = ll(1e18)+1;
const ll MAXN = 1e6;

const int MAX=510000;

int main()
{
    string s;
    map<char,int> m;
    cin>>s;
    rep(i,4)
    {
        m[s[i]]+=1;
    }
    map<char,int>::iterator it;
    for(it=m.begin();it!=m.end();it++)
    {
        if(it->second!=2)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes";
}

Measured memory_bytes: 760
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define INF 1e18
#define max_n 1000000

using namespace std;

void solve()
{
	ll n;
	cin >> n;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
	}
	sort(a, a + n, greater<ll>());
	ll cnt = n - 1, ans = 0, cur = 0;
	while (1)
	{
		if (!cnt)break;
		if (cnt == n - 1)
		{
			cnt--;
			ans += a[cur];
			if (!cnt)break;
			cur++;
		}
		else
		{
			ans += a[cur];
			cnt--;
			if (!cnt)break;
			ans += a[cur];
			cnt--;
			if (!cnt)break;
			cur++;
		}
	}
	cout << ans << endl;
}

int32_t main()
{
	IOS
	ll T = 1;
	// cin>>T;
	for (ll i = 1; i <= T; ++i)
	{
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 5180
import java.util.*;


public class Main {

    private static final int INF = Integer.MAX_VALUE;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        String[] strArray = str.split("");
        List<String> list = new ArrayList<>();

        for (int tmp = 0; tmp < strArray.length ; tmp++) {
            list.add(strArray[tmp]);

        }

        boolean flagfirst = false;
        String a = list.get(0);
        for (int tmp = 1; tmp < list.size() ; tmp++) {
            if(list.get(tmp).equals(list.get(0))){

                list.remove(tmp);
                list.remove(0);
                flagfirst=true;
            }
        }
        boolean secondflag = false;


        if(list.size() == 2){
            if(list.get(0).equals(list.get(1))){
                secondflag = true;
            }

        }
        if(a.equals(list.get(0))) secondflag = false;

        if(flagfirst && secondflag){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }



    }
}


Measured memory_bytes: 21204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define ALL(x) (x).begin(), (x).end()
#define REP(i ,n) for(int i = 0; i < (int)(n); i++)
#define pb push_back
typedef vector<int>vint;
typedef vector<ll>vll;
template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int main()
{
  int N;
  cin >> N;
  vint B(N-1);
  vint C(N);
  cin >> B;
  C[0] = B[0];
  for(int i = 1; i < N-1; i++){
    C[i] = min(B[i-1],B[i]);
  }
  C[N-1] = B[N-2];

  int sum = 0;
  for(auto c : C){
    sum += c;
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <iostream>
#define LL long long
using namespace std;
int main(){
    LL A, B, C; scanf("%lld%lld%lld", &A, &B, &C);
    LL ans=B+min(C, A+B+1); printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SVLL set<vector<LL>>
#define VLL vector<LL>
using namespace std;
typedef long long LL;
int countBlack(SVLL &black, LL a, LL b, LL h, LL w){
    int count = 0;
    for(int i = a - 1; i <= a + 1; i++){
        for(int j = b - 1; j <= b + 1; j++){
            count += black.find(VLL {i, j}) != black.end(); //O(log N)
        }
    }
    return count;
}
void updateBox(SVLL &black, LL *box, LL a, LL b, LL h, LL w){
    for(int i = max((LL)2, a - 1); i <= min(h - 1, a + 1); i++){
        for(int j = max((LL)2, b - 1); j <= min(w - 1, b + 1); j++){
            int t = countBlack(black, i, j, h, w);
            box[t]--;
            box[t + 1]++;
        }
    }
}
int main(){
    LL h, w, n, a, b;
    LL box[10] = {};
    SVLL black;

    cin >> h >> w >> n;
    box[0] = (h - 2) * (w - 2);
    for(int i = 0; i < n; i++){
        cin >> a >> b;
        updateBox(black, box, a, b, h, w);
        black.insert(VLL {a, b});   //O(log N)
    }
    for(auto v: box){
        cout << v << endl;
    }
    return 0;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define ll long long int
#define ff first
#define ss second
#define eps 1e-9

using namespace std;

int main()
{

    ll t,n,m,f,a,b,c,l,r,q,k,x,y,z,ans,mn,mx,sum=0;

    cin>>n;

    vector< pair<ll,ll> > arr(n);

    for(int i=0;i<n;i++)
    {
        cin>>arr[i].ff;
    }

    for(int i=0;i<n;i++)
    {
        cin>>arr[i].ss;
    }

    sort(arr.begin(),arr.end(),[](auto &a,auto &b)
         {
             return (a.ff-a.ss) > (b.ff-b.ss);
         });

         x=y=0;
         ans=0;
         for(int i=0;i<n;i++)
         {
             x+=arr[i].ff;
             y+=arr[i].ss;

             ans = max(ans,x-y);
         }

         cout<<ans<<endl;


}


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>n>>m;
      ans=1900*m+100*(n-m);
      cnt=1;
      rep(i,m)cnt*=2;
      Cout(ans*cnt);
     

       
return 0;
}


Measured memory_bytes: 256
import sys
fin = sys.stdin.readline
sys.setrecursionlimit(500000)

N, M = [int(elem) for elem in fin().split()]
adj = [[] for _ in range(N)]

for _ in range(N + M - 1):
    u, v = [int(elem) - 1 for elem in fin().split()]
    adj[u].append(v)

inv_adj = [[] for _ in range(N)]
for u, neighbors in enumerate(adj):
    for v in neighbors:
        inv_adj[v].append(u)

topo = []
visited = [False] * N

def dfs_visit(node):
    for neighbor in adj[node]:
        if visited[neighbor]:
            continue
        visited[neighbor] = True
        dfs_visit(neighbor)
    topo.append(node)
    return

for node in range(N):
    if not visited[node]:
        visited[node] = True
        dfs_visit(node)

topo = topo[::-1]

parent = [-1] * N
order = dict()
order[topo[0]] = 0
for number, node in enumerate(topo[1:], start=1):
    neighbors = inv_adj[node]
    correct_parent = -1
    for neighbor in neighbors:
        if neighbor in order and order[neighbor] > correct_parent:
            correct_parent = order[neighbor]
    parent[node] = correct_parent
    order[node] = number

order_to_number = {v: k + 1 for k, v in order.items()}
order_to_number[-1] = 0

for i in range(N):
    print(order_to_number[parent[i]])


Measured memory_bytes: 150832
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	int N;
	cin >> N;
	vector<int> A(N);
	vector<int> B(N);
	vector<int> mn(N);
	vector<int> d(N, -1);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	bool f = true;
	for (int i = 0; i < N; i++) {
		if (i == 0 || A[i] > A[i - 1]) {
			d[i] = A[i];
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (i == N - 1 || B[i] > B[i + 1]) {
			if (d[i] != -1 && d[i] != B[i]) f = false;
			d[i] = B[i];
		}
	}
	for (int i = 0; i < N; i++) {
		cerr << d[i] << " ";
	}
	cerr << endl;
	int res = 1;
	if (f) {
		for (int i = 0; i < N; i++) {
			mn[i] = min(A[i], B[i]);
			if (d[i] != -1) {
				if (d[i] > mn[i]) f = false;
			}
			else {
				res = (res*mn[i]) % MOD;
			}
		}
	}
	if (f) {
		cout << res << endl;
	}
	else {
		cout << 0 << endl;
	}
	return 0;

}

Measured memory_bytes: 3328
/*
いくつかの整数が与えられる。最頻値を求めよ。
最頻値が複数ある場合は、小さい順に並べて表示せよ。

やり方：
	・配列(data)に整数を入力。　→　データの数を記録しておく（count）
	・もう一つ配列(answer)を作り、こちらは全て0にしておく。
	・count回繰り返すループを作る。	for(i=0; i<count; i++)
		・配列answerの、[配列data番目]の要素を1増やす。			(dataが 1,1,2,3,4,4,5 だったら、  answerは 0,2,1,1,2,1 )
	・配列answerの、最大値のインデックスを取得して、表示する。


結果：不正解。

*/
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <ctype.h>

int maxindex00(int data[], int from, int to);
void sort01(int data[], int n);

int main()
{
	int maxindex;
	int data[100];
	int result[100]={0};
	int answer[100];
	int i=0,count=0;
	int work;
	while(1){
		if(scanf("%d",&data[i])==EOF){
			break;
		}
		i++;
	}
	count=i;
	for(i=0; i<count; i++){
		result[data[i]]++;
	}
	for(i=0; i<count; i++){
		answer[i]=maxindex00(result, i, count-1);
		work=result[i];
		result[i]=result[answer[i]];
		result[answer[i]]=work;
	}
	sort01(result,count);
	for(i=0; i<count; i++){
		printf("%d\n",answer[i]);
		if(result[i]!=result[i+1]){
			break;
		}
	}
	return 0;
}

void sort01(int data[],int n)
{
	int i,work,maxindex;
	for(i=0;i<n;i++){
		maxindex=maxindex00(data,i,n);
		work=data[i];
		data[i]=data[maxindex];
		data[maxindex]=work;
	}
	return;
}

int maxindex00(int data[], int from, int to)
{
	int i;
	int result=from;
	for(i=from;i<to;i++){
		if(data[result]<data[i]){
			result=i;
		}
	}
	return result;
}

Measured memory_bytes: 592
#include<iostream>
using namespace std;
int main(){
	int A,B,C;
	int i,j,k;
	cin>>A>>B>>C;
	j=0;
	for(i=1;i<B+1;i++){
		if((A*i)%B==C){
			j=1;
		}
	}
	if(j==1){
		cout<<"YES";
	}else{
		cout<<"NO";
	}
}
		
	


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


class dice {
public:
	int tmp,d1, d2, d3, d4, d5, d6;

	void set(int a1, int a2, int a3, int a4, int a5, int a6) {
		d1 = a1;
		d2 = a2;
		d3 = a3;
		d4 = a4;
		d5 = a5;
		d6 = a6;
	}
	
	void e() {
		tmp = d1;
		d1 = d4;
		d4 = d6;
		d6 = d3;
		d3 = tmp;
	}

	void w() {
		tmp = d1;
		d1 = d3;
		d3 = d6;
		d6 = d4;
		d4 = tmp;
	}

	void s() {
		tmp = d1;
		d1 = d5;
		d5 = d6;
		d6 = d2;
		d2 = tmp;
	}

	void n() {
		tmp = d1;
		d1 = d2;
		d2 = d6;
		d6 = d5;
		d5 = tmp;
	}
};

int main() {
	dice d;
	std::string c;

	int a[7], i;

	for (i = 1; i < 7; i++) {
		std::cin >> a[i];
	}

	d.set(a[1], a[2], a[3], a[4], a[5], a[6]);

	std::cin >> c;
	
	for (i = 0; i < c.size(); i++) {
		if (c[i] == 'N') d.n();
		else if (c[i] == 'S') d.s();
		else if (c[i] == 'E') d.e();
		else if (c[i] == 'W')d.w();
		else std::cout << "Error" << std::endl;
	}

	std::cout << d.d1 << std::endl;

	return 0;
		
}


Measured memory_bytes: 3196
#![allow(unused_mut)]
#![allow(non_snake_case)]
#![allow(unused_macros)]
#![allow(unused_variables)]
#![allow(unused_imports)]
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

macro_rules! max {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::max($x, max!($($y),+))
    };
}

macro_rules! min {
    ($x: expr) => ($x);
    ($x: expr, $($y: expr),+) => {
        ::std::cmp::min($x, max!($($y),+))
    };
}

const MOD: usize = 1_000_000_007;
const MAX: usize = 1_000;
use std::cmp;
use std::collections::{HashSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;
fn main() {
    input!{
        N: usize,
    }
    if N == 1 {
        println!("1");
        return;
    }

    let mut is_prime = [true; MAX+1];
    for p in 2.. {
        if p*p > MAX { break; }
        else if is_prime[p] {
            let mut nop = p*p;
            while nop <= MAX {
                is_prime[nop] = false;
                nop += p;
            }
        }
    }

    let mut prime_count = [0; MAX+1];
    for n in 2..N+1 {
        for ((p, _), c) in (0..n+1)
        .zip(is_prime.iter()).zip(prime_count.iter_mut())
        .skip(2).filter(|x| *(x.0).1)
        {
            let mut count = 0;
            let mut res = n;
            while res % p == 0 {
                count += 1;
                res /= p;
            }
            *c += count;
        }
    }
    let ans = prime_count.iter().fold(1, |acc, &c| (acc*(c+1)) % MOD);
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <map>
#include <iomanip>

using namespace std;
typedef long long  ll;

int main() {
	int h, w;
	cin >> h >> w;
	while (h != 0) {
		for (int i = 0; i < h; i++)
		{
			for (int j = 0; j < w; j++)
			{
				if (i == 0 || i == h - 1 || j == 0 || j == w - 1) cout << "#";
				else cout << ".";
			}
			cout << endl;
		}
		cin >> h >> w;
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
int main(){
 
    string S,T;
    cin >> S >> T;
 
    int SS,TT,i,j;
    SS = S.size();
    TT = T.size();
 
    //cout << SS << TT << endl;
    int MIN = 10000;
    int cnt2 = 0;
  
    if(SS == TT){
      for(j=0; j < TT; j++){
        if(S[i+j] != T[j]){
          cnt2++;
        }
      }
      cout << cnt2 << endl;
      return 0;
    }
  
    for(i=0; i < SS-TT; i++){
    int cnt = 0;
 
      for(j=0; j < TT; j++){
        //cout << S[i+j];
        //cout << T[j];
        if(S[i+j] != T[j]){
          cnt++;
        }
      }
      //cout << endl;
      if(MIN >= cnt){
        MIN = cnt;
      }
    }
 
    cout << MIN << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>

int main(){
  int i,j,k,n,m,l;

  scanf("%d %d %d",&n,&m,&l);
  
  long long A[n][m],B[m][l],C[n][l];

  for(i=0; i<n; i++)//A
    for(j=0; j<m; j++)
      scanf("%lld",&A[i][j]);

  for(i=0; i<m; i++)//B
    for(j=0; j<l; j++)
      scanf("%lld",&B[i][j]);

  for(i=0; i<n; i++)
    for(j=0; j<l; j++)
      C[i][j] = 0;

  /*Cを計算*/
  for(i=0; i<n; i++)
    for(j=0; j<l; j++)
      for(k=0; k<m; k++)
	C[i][j] += A[i][k] * B[k][j];

  for(i=0; i<n; i++){
    for(j=0; j<l; j++){
      if(j==0) printf("%lld",C[i][j]);
      else printf(" %lld",C[i][j]);
    }
    printf("\n");
  }

  return 0;
}

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

long long int gcd(long long int x, long long int y){
	if(x%y==0){
		return y;
	}else{
		return gcd(y, x%y);
	}
}

int main() {
	long long int a, b; cin >> a >> b;
	long long int g = gcd(a, b);
	long long int ans = 1LL;
	for(long long int i=2;i*i<=g;i++){
		if(g%i==0){
			ans++;
			while(g%i==0){
				g = g/i;
			}
		}
	}
	if(g!=1) ans++;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main()
{
    ll w,h,n,r,x,y;
    ll a,b,x1,xn,y1,yn;

    cin >> w >> h >> n;

    x1 = 0;
    y1 = 0;
    xn = w;
    yn = h;
    for(int i = 0; i < n; i++)
    {
        cin >> x >> y >> r;

        if(r == 1)
            x1 = max(x, x1);
        else if(r == 2)
            xn = min(x, xn);
        else if(r == 3)
            y1 = max(y, y1);
        else if(r == 4)
            yn = min(y, yn);
    }

    a = xn - x1;
    b = yn - y1;

    if(a < 0 || b < 0)
        cout << 0 << endl;
    else
        cout << a*b << endl;

    return 0;
}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int N;
    static int[] a;

    private static void init() {
        Scanner scanner = new Scanner(System.in);
        N = scanner.nextInt();
        a = new int[N];
        for(int i = 0; i < N; i++) a[i] = scanner.nextInt();

        scanner.close();
    }

    private static boolean check() {

        boolean ok = true;
        for(int i = 0; i < N; i++) {
            if(a[i] % 2 != 0) {
                ok = false;
                break;
            }
        }
        return ok;
    }


    public static void main(String args[]) {
        init();

        int count = 0;
        while (true) {
            if(check()) {
                count++;
                for(int j = 0; j < N; j++) {
                    a[j] = a[j] / 2;
                }
            } else {
                break;
            }
        }

        System.out.println(count);


    }
}


Measured memory_bytes: 21844
N = int(input())

S = input()
CS = S

ans = 0

for i in range(N):

    now = 0
    for j in range(N):

        if S[j] == CS[j]:
            now += 1
        else:
            ans = max(ans, min(i,now) )
            now = 0

    ans = max( ans , min(i,now) )

    CS = " "+CS

print (ans)


Measured memory_bytes: 45788