akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric> //accumulate
#include <queue>
using namespace std;
typedef long long ll;

int n;
int bit[1000010];
void add(int a, int w){
    for (int x = a; x <= n; x += x & -x) bit[x] += w;
}

int sum(int a){
    int ret = 0;
    for (int x = a; x > 0; x -= x & -x) ret += bit[x];
    return ret;
}

int main() {
    int q;
    cin >> n >> q;
    vector<int> com(q), x(q), y(q);
    for (int i = 0; i < q; i++){
        cin >> com[i] >> x[i] >> y[i];
    }

    for (int i = 0; i < q; i++){
        if (com[i] == 0){
            add(x[i], y[i]);
        }
        else{
            cout << sum(y[i]) - sum(x[i] - 1) << endl;
        }
    }

}



Measured memory_bytes: 4448
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
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; }
int main()
{
  int x,n; cin >> x >> n;
  set<int> st;
  rep(i,n) {
    int p; cin >> p;
    st.insert(p);
  }

  int i = 0;
  while(1) {
    if(st.find(x-i) == st.end()) {
      cout << x-i << "\n";
      break;
    }
    if(st.find(x+i) == st.end()) {
      cout << x+i << "\n";
      break;
    }
    i++;
  }
  
  return 0;
}


Measured memory_bytes: 3632
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
import numpy as np
#import operator
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	NKAF=np.array(read().split(),np.int64)
	N=NKAF[0]
	K=NKAF[1]
	AF=NKAF[2:]
	A,F=np.split(AF,2)
	A.sort()
	F.sort()
	F=F[::-1]
	
	lt=0
	rt=10**12+1
	
	Asum=sum(A)
	
	while rt-lt>1:
		mid=(rt+lt)//2
		if Asum-np.minimum(A,mid//F).sum()<=K:
			rt=mid
		else:
			lt=mid
	print(rt if Asum-K>0 else 0)
	
if __name__ == '__main__':
	main()

Measured memory_bytes: 34476
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

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

  int ans = 0;
  for (int i = 0; i < N-1; ++i)
  {
    string str1 = S.substr(0, i);
    string str2 = S.substr(i, N - i);
    int count = 0;

    for (int ch = 'a'; ch != 'z' + 1; ++ch)
    {
      int n1 = str1.find(ch);
      int n2 = str2.find(ch);
      if (n1 != string::npos && n2 != string::npos) ++count;
    }
    ans = max(ans, count);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

public class Main{	
public static void main (String[] args){
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int m = sc.nextInt();
	int[] min = new int[m];
	int[] max = new int[m];
	int bottom = 1;
	int top = n;
	for(int i= 0; i < m; i++){
		min[i] = sc.nextInt();
		max[i] = sc.nextInt();
	}
	for(int i = 0; i < m; i++){
		if(min[i] > bottom) bottom = min[i];
		if(max[i] < top) top = max[i];
	}
	if(top >= bottom){
		System.out.println(top - bottom + 1);
	}else{
		System.out.println(0);
	}
}
}


Measured memory_bytes: 79848
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<complex>
#include<iostream>
#include<sstream>
#include<algorithm>
#include<functional>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);++i)
#define reps(i,j,k) for(int i=j;i<k;++i)
typedef long long ll;
typedef unsigned long long ull;
char stage[128][128];
int w,h;
void dfs(int y,int x){
	char med = stage[y][x];
	stage[y][x] = '.';
	rep(i,4){
		if(stage[y+dy[i]][x+dx[i]] == med)dfs(y+dy[i],x+dx[i]);
	}
	return ;
}
int main(){
	while(scanf("%d%d",&h,&w), h|w){
		memset(stage,0,sizeof(stage));
		rep(i,h)scanf("%s",stage[i]);
		int res = 0;
		rep(i,h){
			rep(j,w){
				if(stage[i][j] != '.'){
					dfs(i,j);
					res++;
				}
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

Measured memory_bytes: 1680
#[allow(unused_imports)]
use std::collections::HashSet;

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn main() {
    let hw = read_vec::<usize>();
    let h = hw[0];
    let w = hw[1];

    let mut masu : Vec<Vec<char>> = Vec::with_capacity(h);
    for _i in 0..h {
        let s : Vec<char> = read::<String>().chars().collect();
        masu.push(s);
    }

    let answer = solve(h, w, &masu);
    println!("{}", answer);
}

fn solve(h: usize, w: usize, masu: &[Vec<char>]) -> usize {

    let mut dp : Vec<Vec<(usize, usize)>> = vec![vec![(0, 0);w];2];
    let mut max = 0;
    for i in 0..h {
        for j in 0..w {
            let curr = i % 2;

            if masu[i][j] == '#' {
                dp[curr][j] = (0, 0);
                continue;
            }

            // yoko
            if j == 0 || masu[i][j-1] == '#' {
                let mut j1 = j + 1;
                while j1 < w && masu[i][j1] != '#' {
                    j1 += 1;
                }
                dp[curr][j].0 = j1 - j - 1; 
            } else {
                dp[curr][j].0 = dp[curr][j-1].0;
            }

            // tate
            if i == 0 || masu[i-1][j] == '#' {
                let mut i1 = i + 1;
                while i1 < h && masu[i1][j] != '#' {
                    i1 += 1;
                }
                dp[curr][j].1 = i1 - i - 1;
            } else {
                let prev = (i-1) % 2;
                dp[curr][j].1 = dp[prev][j].1;
            }

            let val = dp[curr][j].0 + dp[curr][j].1;
            if val > max {
                max = val;
            }
        }
    }
    return max + 1;
}


Measured memory_bytes: 20732
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll len;
    string str;
    cin>>len>>str;
    ll count[26];
    for(ll i=0;i<26;i++)
    {
        count[i]=1;
    }
    for(ll i=0;i<len;i++)
    {
        count[str[i]-'a']++;
    }
    ll val=1;
    for(ll i=0;i<26;i++)
    {
        val=(val*count[i])%MOD;
    }
    val--;
    cout<<val;
    return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<queue>
#include<functional>
#include<iso646.h>
#include<bitset>

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg)/360)*2*M_PI)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
	ll N, K;
	cin >> N >> K;
	if (N > K) {
		N = N % K;
	}
	cout << min(N, K - N) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#include<string>
#include<bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#include<vector>
#define rep2(i,x,n) for(int (i)=(x);(i)<(n);(i)++)

int main(){
   string s;
   cin >> s;
   if (s == "Sunny"){
     cout << "Cloudy" << endl;
   }
   else if(s == "Cloudy"){
     cout << "Rainy" << endl;
   }
   else {
     cout << "Sunny" << endl;
   }
}


Measured memory_bytes: 256
# include <iostream>
# include <stack>
# include <iomanip>

int main() {
	int n;
	std::stack<int> s;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		int input;
		std::cin >> input;
		s.push(input);
	}
	for (int i = 0; i < n; i++) {
		if( i != n-1)
			std::cout << s.top() << " ";
		if (i == n - 1)
			std::cout << s.top();
		s.pop();
	}
        std::cout << std::endl; 
	return 0;
}

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

c=0
while not (A[0]<A[1]<A[2]) and c<K:
    if A[0]>=A[1]:
        A[1]=A[1]*2
        c+=1
    elif A[1]>=A[2]:
        A[2]=A[2]*2
        c+=1
    #print(A)

print(['No','Yes'][A[0]<A[1]<A[2]])

Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <vector>
#include <math.h>

using namespace std;

typedef long long int ll;
typedef long double ld;

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define vsort(a) sort(a.begin(), a.end())
#define rev(a) reverse(a.begin(), a.end())

const int MOD = 1000000007;
const int INF = INT_MAX;


int main(){

    int n;
    cin >> n;
    if (n==1) cout << "Hello World" << endl;
    else {
        int a, b;
        cin >> a >> b;
        cout << a+b << endl;
    }


    return 0;
}





//              g++ -std=c++1z

Measured memory_bytes: 384
#pragma GCC optimize("O2,Ofast,inline,unroll-all-loops,-ffast-math")
#include <bits/stdc++.h>
#define pb(X) push_back(X)
using namespace std;

int n, a, b, c, d, q, ans;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	for (int i = 0 ; i < s.length(); ++i) cout <<'x';
	return 0;
}

Measured memory_bytes: 256
list =input().split() #
var=[]
for a in list:
  a = int(a)
  var.append(a)
flg = False

if 1 in var:
    if 9 in var:
        if 7 in var:
             if 4 in var:
                 flg = True
if flg:
    print("YES")
else:
    print("NO")


Measured memory_bytes: 2940
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include<math.h>
using namespace std;

 int main(){
   int n; cin >> n; int mi=10e5;
   
   for(int j=n;j<n+300;j++){
     
    string s = to_string(j);
    if(s[0]==s[1]&&s[1]==s[2]) mi=min(mi,j);
   }
   cout << mi <<endl;
 }

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;
typedef string::const_iterator State;
class ParseError {};

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll INM = 114514;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-12;

template <typename T>
void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}
inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}
ll powm(ll a, ll b, ll c) {
	if (b == 0)
		return 1;
	else if (b % 2 == 0) {
		ll d = powm(a, b / 2, c);
		return (d * d) % c;
	} else
		return (a * powm(a, b - 1, c)) % c;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll dx[4] = {1, 0, -1, 0};
ll dy[4] = {0, 1, 0, -1};

ll dp[114514][13] = {};
ll m[114514]	  = {}; //10-i mod 13
int main() {
	IOS();
	string s;
	cin >> s;
	int n	= s.size();
	dp[0][0] = 1;
	for (int i = 0; i < n; i++) {
		m[i] = powm(10, n - i - 1, 13);
	}
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < 13; j++) {
			if (s[i] == '?') {
				for (int k = 0; k < 10; k++) {
					int l = (k * m[i]) % 13;
					dp[i + 1][j] += dp[i][mod(j - l, 13)];
					dp[i + 1][j] %= MOD;
				}
			} else {
				int k = s[i] - '0';
				k *= m[i];
				k %= 13;
				dp[i + 1][j] += dp[i][mod(j - k, 13)];
				dp[i + 1][j] %= MOD;
			}
		}
	}
	dump(dp[n][5]);
	return 0;
}


Measured memory_bytes: 12624
/*An anomaly, I'm Muhammad Ali
  'Cause I know one day I'm gonna be the*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const  int mod = 1000000007;
void add(ll& a, ll b)
{
    a+=b;
    while(a>=mod)
        a-=mod;
    while(a<0)
        a+=mod;
    
}

int main()
{
	
	int n, a,b;
	cin>>n>>a>>b;
	int dp[n][n];
	map<int,int> f;
	a--;
	b--;
	for(int i = 0 ; i < n; i++)
	{
		for(int j = 0; j < n ;j++)
		{
			dp[i][j] = abs(j-i);
		}
	}
	
	for(int i = a+1 ; i < n ; i++ )
		dp[a][i] = min(dp[a][i], 1 + dp[b][i]);
	for(int i = 0 ;i < n ; i++)
		for(int j = i+1 ; j < n; j++)
			dp[i][j] = min(dp[i][j], dp[i][a]+dp[a][j]);
	
	for(int i = 0 ; i < n; i ++)
		for(int j = i+1 ; j < n ; j++)
			f[dp[i][j]]++;
	for(int i = 1 ; i < n ; i++)
	{
		cout<<f[i]<<endl;
	}
  	return 0;
}

Measured memory_bytes: 16000
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define rep(i,N) for(short i=0;i<(short)N;i++)
#define Swap(a,b) (a+=b,b=a-b,a-=b)
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline short IN(void)
{
  short x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(short a)
{
  if(a<0)putchar('-'),a=-a;
  short d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){putchar(d[i]+48);}putchar('\n');
}
static inline short Max(short x,short y){return x>y?x:y;}
short work[9999][3],sz=0;
static inline void Add(short x,short y,short v){work[sz][0]=x;work[sz][1]=y;work[sz++][2]=v;}
int main(void)
{
  short N=IN(),A[3*N],dp[N][N],B[N],mx,extra=0;
  rep(i,3*N)A[i]=IN()-1;
  memset(B,-0x3f,sizeof(B));memset(dp,-0x3f,sizeof(dp));
  dp[A[0]][A[1]]=dp[A[1]][A[0]]=B[A[0]]=B[A[1]]=mx=0;
  rep(i,N-1)
  {
    short k=3*(i+1);
    if(A[k-1]>A[k])Swap(A[k-1],A[k]);
    if(A[k]>A[k+1])Swap(A[k],A[k+1]);
    if(A[k-1]>A[k])Swap(A[k-1],A[k]);
    short x[3]={A[k-1],A[k],A[k+1]};
    if(x[2]==x[0]){extra++;continue;}
    if(x[0]==x[1])rep(j,N)Add(j,x[2],dp[j][x[0]]+1);
    if(x[1]==x[2])rep(j,N)Add(j,x[0],dp[j][x[1]]+1);
    rep(j,3)Add(x[j==0],x[j==2?1:2],dp[x[j]][x[j]]+1);
    rep(j,3)rep(k,j)Add(x[j],x[k],mx);
    rep(j,N)rep(k,3)Add(j,x[k],B[j]);
    rep(j,sz)
    {
      if(dp[work[j][0]][work[j][1]]<work[j][2])
      {
        dp[work[j][0]][work[j][1]]=dp[work[j][1]][work[j][0]]=work[j][2],
        B[work[j][0]]=Max(B[work[j][0]],work[j][2]),
        B[work[j][1]]=Max(B[work[j][1]],work[j][2]),mx=Max(mx,work[j][2]);
      }
    }
    sz=0;
  }
  return OUT(Max(mx,dp[A[3*N-1]][A[3*N-1]]+1)+extra),0;
}

Measured memory_bytes: 9356
fn main() {
    let mut sc = Scanner::new();
    let s: Vec<char> = sc.read::<String>().chars().collect();
    if s[0] == s[s.len() - 1] {
        if s.len() % 2 == 0 {
            println!("First");
        } else {
            println!("Second");
        }
    } else {
        if s.len() % 2 == 0 {
            println!("Second");
        } else {
            println!("First");
        }
    }
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner {
            ptr: 0,
            length: 0,
            buf: vec![0; 1024],
            small_cache: vec![0; 1024],
        }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool {
        b == b'\n' || b == b'\r' || b == b'\t' || b == b' '
    }

    fn read<T>(&mut self) -> T
    where
        T: std::str::FromStr,
        T::Err: std::fmt::Debug,
    {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)])
                    .parse()
                    .unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}


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

int main(){
  int n = 0;
  int k = 0;
  string s;
  cin >> n >> k >> s;
  vector<char> vec(n);
  for(int i = 0; i < n; i++){
    vec[i]=s[i];
  }
  vec[k-1]=tolower(vec[k-1]);
  for(int i = 0; i < n; i++){
    cout << vec[i];
  }
}

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

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int sum = 0;
  for(int i = 0 ; i < N ; i++){
    int t; cin >> t;
    if(A <= t && t < B)continue;
    sum++;
  }
  cout << sum << endl;
  return 0;
}


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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

string s;
ll k;

int main(void) {
  // Here your code !
  cin >> s;
  scanf("%lld", &k);

  int n = s.size();

  for (int i = 0; i < n - 1; ++i) {
    if (s[i] == 'a') continue;
    
    int cost = (int)('z' - s[i]) + 1;

    if ((ll)(cost) > k) {
      continue;
    }

    s[i] = 'a';
    k -= cost;
  }

  int cur_pos = (int)(s.back() - 'a');

  k += (ll)(cur_pos);
  
  int mod = (int)('z' - 'a') + 1;

  int last_pos = k % mod;

  s[n - 1] = (char)('a' + last_pos);

  cout << s << endl;

  return 0;
}


Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <utility>
#include <cstring>
using namespace std;
typedef long long ll;

int N,M;
vector<vector<int>> nextT;
vector<int> depth;
vector<int> ord;

void dfs(int cur) {
	if (depth[cur] > 0) return;
	int d = 1;
	for (int n : nextT[cur]) {
		dfs(n);
		d = max(d, depth[n] + 1);
	}
	depth[cur] = d;
	ord.push_back(cur);
}

int main() {
	scanf("%d %d", &N, &M);
	depth.assign(N, -1);
	nextT.resize(N);
	int I,J;
	for (int i = 0; i < M; ++i) {
		scanf("%d %d", &I, &J);
		nextT[I-1].push_back(J-1);
	}
	for (int i = 0; i < N; ++i) {
		dfs(i);
	}
	int maxDepth = 0;
	for (int i = 0; i < N; ++i) {
		maxDepth = max(maxDepth, depth[i]);
	}
	for (int i = 0; i < N; ++i) {
		printf("%d\n", ord[N-1-i]+1);
	}
	printf("%d\n", maxDepth == N ? 0 : 1);
}

Measured memory_bytes: 2184
#!/usr/bin/python3
# -*- coding: utf-8 -*-
n, k = map(int, input().split())
while(True):
    if n - k > 0:
        if n // k > 0:
            n = n - k * (n // k)
        else:
            if n - k < n:
                n = n - k
            else:
                break
    else:
        if abs(n - k) < n:
            n = abs(n - k)
        else:
            break

print(n)

Measured memory_bytes: 2940
#include <cstdio>
#include <vector>
#define MAX 10
using namespace std;

vector<int> sort(vector<int> &array);

int main(){
	vector<int> array;
	int n;
	
	for(int i = 0; i < MAX; i++){
		scanf("%d", &n);
		array.push_back(n);
	}
	
	sort(array);
	
	for(int i = 0; i < 3; i++){
		printf("%d\n", array[i]);
	}
	return 0;
}

vector<int> sort(vector<int> &array){
    int temp = 0;
    for(int i = 0; i < array.size(); i++){
        for(int j = 0; j < array.size() - i - 1; j++){
            if(array[j] < array[j + 1]){
                temp = array[j];
                array[j] = array[j + 1];
                array[j + 1] = temp;
            }
        }
    }
    return array;
}

Measured memory_bytes: 1056
#include<stdio.h>
#include<stdlib.h>

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

typedef struct{
    int priority;
    double value;
}data;

//昇順
int asc(const void* a, const void* b){
    return *(int*)a-*(int*)b;
}

//降順
int desc(const void* a, const void* b){
    return *(int*)b-*(int*)a;
}

int main(void){
    int N;
    scanf("%d",&N);
    char S[N+1];
    scanf("%s",S);

    //0~i-1までで、Wを向いている人の数(W[0]=0)
    int W[N];
    W[0]=0;
    for(int i=1;i<N;i++){
        if(S[i-1]=='W') W[i]=W[i-1]+1;
        else W[i]=W[i-1];
    }
    
    //i+1~Nまでで、Eを向いている人の数(E[N-1]=0)
    int E[N];
    E[N-1]=0;
    for(int i=N-2;i>=0;i--){
        if(S[i+1]=='E') E[i]=E[i+1]+1;
        else E[i]=E[i+1];
    }
    
    int ans=N;
    for(int i=0;i<N;i++){
        ans=MIN(ans,W[i]+E[i]);
    }
    printf("%d\n",ans);
    
    return 0;
}

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

int main() {
    int k, x;
    cin >> k >> x;

    if (500*k >= x) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


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

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

void mainmain(){
	set<int> se;
	rep(i,3){
		int a;
		cin>>a;
		se.insert(a);
	}
	cout<<se.size()<<endl;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(20);
    mainmain();
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <iomanip>
#include <map>
#include <stack>
#include <queue>

using namespace std;

typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n,h[30];
    cin>>n;
    for(int i=0;i<n;i++) cin>>h[i];
    
    int m=h[0];
    int ans=0;
    for(int i=0;i<n;i++){
        if(h[i]>=m){
            m=h[i];
            ans++;
        }
    }
    cout<<ans<<endl;
}

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

#define int long long int
#define rep(a,b,c) for(int a=b;a<c;a++)
#define repm(a,b,c) for(int a=(b-1);a>=c;a--)
#define pb push_back
#define str string
#define sf(a) scanfs("%d",&a)
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()

using namespace std;

const int INF = 1e18 + 9;
const int Mod = 1e9 + 7;
inline int replac(str s){double ans=0;rep(i,0,s.length()){ans+=(s[i]-'0')*pow(10,s.length()-i-1);}return (int)ans;}
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<pii> vii;

int cost[200][200];
int d[200];
bool used[200];
int V;

void dijkstra(int s){
    fill(d,d+V,INF);
    fill(used,used+V,false);
    d[s] = 0;

    while(true){
        //    cout << "a";
        int v = -1;

        rep(u,0,V){
            if(!used[u]&&(v==-1||d[u]<d[v]))v=u;
        }

        if(v==-1)break;
        used[v] = true;
        rep(u,0,V){
            d[u] = min(d[u], d[v] + cost[v][u]);
        }
    }
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    while(true){
        rep(j,0,105){
            rep(k,0,105)cost[j][k]=INF;
        }
        cin >> n >> k;
        V=n;
        if(!n&&!k)break;
        rep(i,0,k){
            int a,b,c,l;
            cin >> a >> b >> c;
            b--;c--;
            if(a==1){
                cin >> l;
                cost[b][c]=min(cost[b][c],l);
                cost[c][b]=min(cost[c][b],l);
            }else{
                dijkstra(b);
                if(d[c]==INF)cout << -1 << endl;
                else cout << d[c] << endl;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 3324
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a{1};
  while ((int)a.size() < n - 1) {
    set<int> se(begin(a), end(a));
    for (int e : a) for (int f : a) if (e < f) {
      se.insert(e + f);
    }
    for (int x = a.back(); ; ++x) if (!se.count(x)) {
      bool ok = true;
      for (int e : a) {
        if (se.count(x + e)) {
          ok = false;
          break;
        }
      }
      if (ok) {
        a.push_back(x);
        break;
      }
    }
  }
  auto fn = [&](const auto& fn, int n) -> VV<lint> {
    if (n == 2) {
      return {{0, 1}, {1, 0}};
    }
    auto res = fn(fn, n - 1);
    lint mx = 0;
    {
      V<> vs(n - 1);
      iota(begin(vs), end(vs), 0);
      do {
        lint curr = 0;
        int p = -1;
        for (int v : vs) {
          if (p != -1) curr += res[p][v];
          p = v;
        }
        mx = max(mx, curr);
      } while (next_permutation(begin(vs), end(vs)));
    }
    V<lint> v;
    for (int i = 0; i < n - 1; ++i) {
      res[i].push_back(a[i] * (mx + 1));
      v.push_back(res[i].back());
    }
    v.push_back(0);
    res.push_back(v);
    return res;
  };
  for (const auto& v : fn(fn, n)) {
    for (int i = 0; i < n; ++i) {
      cout << v[i] << " \n"[!(n + ~i)];
    }
  }
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
max_ = 0

pre = -1
count = 0
for i in range(n):
    if pre >= h[i]:
        count += 1
    else:
        count = 0
    pre = h[i]
    max_ = max(max_, count)
print(max_)


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

int main(){
  int A,B;
  cin >> A >> B;
  if(A >= 13){
    cout << B << endl;
  }
  else if(A >= 6){
    cout << B/2 << endl;
  }
  else{
    cout << 0 << endl;
  }
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 3000 + 50;
const int mod = 1e9+7;
char s[maxn],t[maxn];
int dp[maxn][maxn];
int main(){
    scanf("%s", s+1);
    scanf("%s", t+1);
    int l1, l2;
    l1 = strlen(s+1);
    l2 = strlen(t+1);
    for(int i = 1; i <= l1; i++)
        for(int j = 1; j <= l2; j++){
            if(s[i] == t[j]) dp[i][j]=dp[i-1][j-1]+1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    int n = dp[l1][l2];
    char temp[maxn];
    int c = 0;
    int i = l1, j = l2;
    while(n>0){
        int c1 = dp[i-1][j];
        int c2 = dp[i][j-1];
        int c3 = dp[i-1][j-1];
        if(c3 + 1 == n && s[i] == t[j]){
            temp[c++] = s[i];
            i--;j--;
            n = c3;
        }
        else{
            if(n == c1){
                i--;
            }
            else j--;
        }
    }
    for(--c; c >= 0; c--)printf("%c", temp[c]);
    return 0;
}





Measured memory_bytes: 35968
using System;
using static System.Console;
using static System.Math;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = tmp[0];
            int B = tmp[1];
            WriteLine(B % A ==0 ? A + B : B - A);
        }
    }
}

Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define int ll
#define pb push_back
#define setbits(x)          __builtin_popcountll(x)
#define endl "\n"
typedef long long ll;

void solve()
{
    int n;
    cin>>n;
    map<string ,int> mp;
    for(int i=0;i<n;i++)
    {
        string str;
        cin>>str;
        mp[str]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
    return 0;
}


Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int r = sc.nextInt();
        int D = sc.nextInt();
        long x = sc.nextLong();

        for (int i = 2001; i <= 2010; i++)
        {
            x = r * x - D;
            Console.WriteLine(x);
        }
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
        return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
        var tmp = ReadIntArray();
        int h = tmp[0], w = tmp[1];
        string[] g = new string[h];
        for (int i = 0; i < h; i ++)
        {
            g[i] = ReadLine();
        }

        long[,] dp = new long[h, w];
        for (int i = 0; i < w && g[0][i] == '.'; i++) dp[0,i] = 1;
        for (int i = 0; i < h && g[i][0] == '.'; i++) dp[i,0] = 1;

        int M = 1000000007;

        for (int i = 1; i < h; i++)
        {
            for (int j = 1; j < w; j++)
            {
                if (g[i][j] == '.')
                    dp[i, j] = (dp[i-1, j] + dp[i, j-1]) % M;
            }
        }

        WriteLine(dp[h-1, w-1]);
    }
}

Measured memory_bytes: 29020
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
 
using llong = long long;
using ld = long double;
using ii = pair<int, int>;
using ull = unsigned long long;
using pll = pair<llong, llong>;
using vi = vector<int>;
 
 
#define endl "\n"
#define fi first
#define se second
#define left LEVO
#define right PRAVO
#define time CHAS
#define all(a) (a).begin(), (a).end()
#define prev PAPEREDNIKXD
#define next NASTUPNIKXD
#define pb push_back
#define deb cout<<"CHECK\n";
#define last(a) (a)[(a).size()-1]
 
#define elif else if
#define cclear cout<<flush;
#define fclear fflush(stdout);
#define x_files freopen("exam.in","r",stdin);freopen("exam.out","w",stdout);
#define kchay ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
 
const llong over999 = 1e14;
const ld eps = 1e-9;
const int base = 1000*1000;
const ld Pi = acos(-1);
const llong md = 1e9+7;
const llong ya = 0;
 
/*.st*/
 
llong n, x, cnt, ff;
int main() {
    kchay;   
    //x_files;
    
    cin >> n;
    
    for(int i = 0; i < n; i++)
    {
        cin >> x;
        if(x && x%4==0)cnt++; 
            elif(x && x%2==0)ff++;
    }
    ff -= ff&1;
    if(cnt >= (n-ff)/2)cout << "Yes"; else cout << "No";
    cout << endl;
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int[] ia = readNums();
		int a = ia[0];
		int b = ia[1];
		int ans = 0;
		for (int i = a; i <= b; i++) {
			if (i / 10000 == i % 10) {
				if (i / 1000 % 10 == i / 10 % 10) {
					ans++;
				}
			}
		}
		pln(ans);
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 21332
// ABC Swap
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define repr(i,x,n) for(int i=x; i<(int)n; i++)

int main() {
    int X,Y,Z; cin >> X >> Y >> Z;
    cout << Z <<' '<< X  << ' ' << Y;
}

Measured memory_bytes: 3644
import Control.Applicative

main = do
 [a,b,c,d] <- map read.words <$> getLine :: IO [Int]
 putStrLn $ answer d [abs(a-b), abs(b-c), abs (a-c)]

answer d [ab,bc,ca] = if all (<=d) [ab,bc] || ca <= d then "Yes" else "No"

Measured memory_bytes: 508
mod=10**9+7
n,a,b,c=map(int,input().split())
invc=100*pow(100-c,mod-2,mod)
invc%=mod
a*=invc*pow(100,mod-2,mod)
a%=mod
b*=invc*pow(100,mod-2,mod)
b%=mod
fact=[1]
for i in range(1,2*n):
  fact.append((fact[-1]*i)%mod)
revfact=[1]
for i in range(1,2*n):
  revfact.append(pow(fact[i],mod-2,mod))
ans=0
for i in range(n,2*n):
  ways_a=fact[i-1]*revfact[n-1]*revfact[i-n]*pow(a,n,mod)*pow(b,i-n,mod)
  ways_b=fact[i-1]*revfact[n-1]*revfact[i-n]*pow(b,n,mod)*pow(a,i-n,mod)
  ans+=i*(ways_a+ways_b)*invc
  ans%=mod
print(ans)

Measured memory_bytes: 24760
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<iostream>
#define LL long long
using namespace std;
int main()
{
	LL n, a, b;
	scanf("%lld%lld%lld", &n, &a, &b);
	if(((b-a)&1) == 0) 
	{
		printf("%lld", ((a+b)>>1) - min(a, b));
		return 0;
	}
	else
	{
		LL tmpa = (a+b)>>1, tmpb = tmpa + 1;
		LL ans = min(min(tmpa, tmpb)-1, n-max(tmpa, tmpb)) + 1;
		printf("%lld", ans);
	}
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

#define INF (1e9)

float A, B;

int main() {
    cin >> A >> B;
    cout << ceil((B - 1) / (A - 1)) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
long long int factorial(long long int x){
  return x==0 ? 1 : x*factorial(x-1);
}
int main(){
  long long i, j, h, w, ct=-1, tmp=0;
  cin >> h >>w;
  char a[h][w];
  for(i=0; i<h; i++)
    for(j=0; j<w; j++)
      cin >> a[i][j];
  for(i=0; i<h; i++)
    for(j=0; j<w; j++){
      if(a[i][j]=='#'){
	if(i+j==ct+1&&(i==tmp+1||i==tmp)){
	  ct++;
	  tmp=i;
	}
	else{
	  cout << "Impossible";
	  return 0;
	}
      }
    }
  cout << "Possible";
  return 0;
}


Measured memory_bytes: 256
while True:
	a, op, b=input().split()
	a = int(a)
	b = int(b)
	if op == "+":
		print(a + b)
	elif op == "-":
		print(a - b)
	elif op == "*":
		print(a * b)
	elif op == "/":
		print(a // b)
	else:
		break



Measured memory_bytes: 5596
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
//cout<<fixed<<setprecision(15)<<ans;
 
template <typename T>
void printvec(vector<T>& vec){
	for(int i=0;i<vec.size();i++){
		cout<<vec[i]<<" ";
	}
	cout<<endl;
}

vector<vl> adj(212345);
ll neigh[212345][2];
ll value[212345];
ll haha[212345];
ll remov[212345];
ll u[212345],v[212345];
set<pll> seti;
set<pll>::iterator it;
int main(){
    std::ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    ll i,j;
    string s;
    cin>>s;
    //ll u,v;
    rep(i,m){
    	cin>>u[i]>>v[i];
    	u[i]--;
    	v[i]--;
    	adj[u[i]].pb(i);
    	adj[v[i]].pb(i);
    	neigh[u[i]][s[v[i]]-'A']++;
    	neigh[v[i]][s[u[i]]-'A']++;
    }
    pll papa;
    rep(i,n){
    	value[i]=neigh[i][0]*neigh[i][1];
    	papa=mp(value[i],i);
    	seti.insert(papa);
    }
    ll wow,edj,lol;
    while(!seti.empty()){
    	it=seti.begin();
    	papa=*it;
    	if(papa.ff!=0){
    		break;
    	}
    	// rep(i,n){
    	// 	if(!remov[i]){
    	// 		cout<<value[i]<<" ";
    	// 	}
    	// }
    	// cout<<endl;
    	//cout<<papa.ss<<endl;
    	remov[papa.ss]=1;
    	seti.erase(it);
    	wow=papa.ss;
    	//cout<<wow<<endl;
    	rep(i,adj[wow].size()){
    		edj = adj[wow][i];
    		if(!haha[adj[wow][i]]){
    			haha[adj[wow][i]]=1;
    			lol=u[edj]^v[edj]^wow;
    			if(!remov[lol]){
    				seti.erase(mp(value[lol],lol));
    				neigh[lol][s[wow]-'A']--;
    				value[lol]=neigh[lol][0]*neigh[lol][1];
    				seti.insert(mp(value[lol],lol));
    			}
    		}
    	}

    }
    if(!seti.empty()){
    	cout<<"Yes"<<endl;
    }
    else{
    	cout<<"No"<<endl;
    }

    return 0;   
}



Measured memory_bytes: 35024
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<stdio.h>
using namespace std;

int main()
{
 double x1, y1, x2, y2, x3, y3, xp, yp, a, b, c;
 while(cin>>x1>>y1>>x2>>y2>>x3>>y3>>xp>>yp)
 {
	 a = (x2-x1)*(yp-y1)-(y2-y1)*(xp-x1);
     b = (x3-x2)*(yp-y2)-(y3-y2)*(xp-x2);
     c = (x1-x3)*(yp-y3)-(y1-y3)*(xp-x3);
	 if((a>0&&b>0&&c>0)||(a<0&&b<0&&c<0))
		 cout<<"YES"<<endl;
	 else
		 cout<<"NO"<<endl;
 }
 return 0;
}

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


int main() {
    int n;
    cin >> n;
    int t,a;
    cin >> t >> a;
    vector<double> h(n,0);
    rep(i,n){
        int high = 0;
        cin >> high;
        h.at(i) = abs(a-(t-high*0.006));
    }
    int ind_memo = 0;
    rep(i,n)if(h[ind_memo] > h[i])ind_memo = i;
    cout << ind_memo+1 << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
w = int(raw_input())
n = int(raw_input())

ans = [i for i in range(1, w+1)]

for i in range(n):
  a, b = map(int, raw_input().split(','))

  ans[a-1], ans[b-1] = ans[b-1], ans[a-1]

for i in range(w):
  print ans[i]

Measured memory_bytes: 6248
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  string s;
  cin >> s;
  rep(i, s.size()) rep(j, i + 1, s.size()){
    if (s[i] == 'C' && s[j] == 'F'){
      cout << "Yes\n";
      return 0;
    }
  }
  cout << "No\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i < (n);i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define SCANF(i) int i;scanf("%d",&i)
typedef long long ll;
using namespace std;
using P = pair<int,int>;
const long long INF = 1LL << 60;
const int IINF=100000000;
const int MOD = (int)1e9 + 7;
//約数列挙
vector<long long> divisor(long long n) {
    vector<long long> ret;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) ret.push_back(n / i);
        }
    }
    //sort(ret.begin(), ret.end()); // 昇順に並べる
    return ret;
}
vector<int> dx={1,0,-1,0};vector<int> dy={0,-1,0,1};

signed main () {
    float a,b,c;cin >> a >> b >> c;
    if((a/c) <= b)cout << "Yes" << endl;
    else cout << "No" << endl;
}//https://atcoder.jp/contests/abc177/tasks/abc177_a

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

using namespace std;

#define PI          3.1415926535897932384626433832795l

#define pb push_back
#define mp make_pair
#define lb lower_bound // First element which is not less than val
#define ub upper_bound // First element greater than val
#define f first
#define s second

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
using vpll = vector<pair<ll,ll>>;

using pii = pair<int,int>;
using pll = pair<ll,ll>;

#define endl '\n'
#define re return

#define rep(i,a,b) for (ll i = (a); i < (b); i++)
#define repz(i, a) for (ll i = 0; i < (a); i++)
#define repd(i,a,b) for (ll i = (a); i >= b; i--)
#define repdz(i,a) for (ll i = a; i >=0; i--)
#define trav(a, x) for (auto& a : x)

#define vecin(n,v) for(ll i = 0; i < n; i++) cin>>v[i];
#define llin(a) ll a; cin>>a;
#define llin2(a,b) ll a,b; cin >>a>>b;
#define llin3(a,b,c) ll a,b,c; cin>>a>>b>>c;
#define full(v) v.begin(),v.end()

void solve()
{
    ll n,k;
    cin >> n >> k;
    if (n > k)
        n %= k;
    if (n > k/2)
        n  = abs(k-n);

    cout << n << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    //llin(t);
    //while (t--)
    //{
        solve();
    //}
}


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

signed main() {
int N;
cin >> N;
string S, T;
cin >> S >> T;

int ans = 2*N;
int count = 1;
while( N - count >= 0 ){
if( S.substr(N-count, count) == T.substr(0, count) ){
ans = 2*N - count;
}
count++;
}

cout << ans << endl;
            
}


Measured memory_bytes: 256